Pacific-Design.com

    
Home Index

1. Binary Search Tree

2. 2 Depth First Search

Binary Search Tree / 2 Depth First Search /

Graph Traversal - Depth First Search O(V+E)

Searching a node and its children before going to its siblings.

public class DepthFirstSearch {

    public void search(Node root) {

        if(root == null) return;
        visit(root);
        root.visited = true;

        foreach(Node node in root.adjacent) {
            if(node.visited == false) {
                search(node);
            }
        }
    }
}

Graph Searches in Java

http://algs4.cs.princeton.edu/40graphs/