Depth-first traversal

Back to Graph traversal

The depth-first traversal is an algorithm for traversing the vertices of a graph. The DepthFirst_GraphTraversal class provides an algorithm-object for depth-first traversal.

Algorithm

The algorithm first pushes all the seed vertices at the back of a stack. As long as there is a vertex at the back of the stack, the algorithm marks , removes from the stack, and then pushes all the unmarked adjacent vertices of at the back of the stack.

This description parallels that for the breadth-first search. However, the traversal is commonly implemented by recursive function calls for efficiency; the stack is then implicit as the function call stack.

Files

Depth-first search module

Depth-first traversal of a graph

Testing for depth-first traversal