Depth first search ( dfs )
Depth first search ( dfs )
GRAPH TRAVERSAL
• Traversal of a graph is a systematic walk that visits all the vertices in a
specific order.
• There are mainly two different ways of traversing a graph :
a) Breadth-first traversal
b) Depth-first traversal
• Rule 1 − Visit the adjacent unvisited vertex. Mark it as visited. Display it. Push
it in a stack.
• Rule 2 − If no adjacent vertex is found, pop up a vertex from the stack. (It will
pop up all the
vertices from the stack, which do not have adjacent vertices.)