next up previous
Next: Depth-First Search Up: Easy Graph Problems Previous: Graph Terminology

Traversing a Graph

Key idea: mark each vertex when it's visited, keep track of what's been explored. Vertex can exist in one of three distinct states; UNDISCOVERED, DISCOVERED, and FULLY-EXPLORED. Undiscovered means a vertex has not previously been visited. Discovered means the vertex has been visited before, however not all edges leading away from the vertex have been explored. Fully-explored means that the vertex has no unexplored edges attached to it. Maintain a structure of vertices which are discovered but not fully-explored. A queue structure, FIFO, would mean performing a breadth first search, while a stack structure, LIFO, would mean performing a depth first search. Regardless of what order, every edge must be considered twice.



Nitin Sharma
Wed Oct 8 17:46:14 PDT 1997