• Tutorials
  • DSA
  • Data Science
  • Web Tech
  • Courses
June 01, 2022 |17.8K Views

Iterative Depth First Traversal of Graph

  Share   Like
Description
Discussion

Depth First Traversal (or Search) for a graph is similar to Depth First Traversal (DFS) of a tree. The only catch here is, unlike trees, graphs may contain cycles, so a node might be visited twice. To avoid processing a node more than once, use a boolean visited array.

Example:  

Input: n = 4, e = 6 
0 -> 1, 0 -> 2, 1 -> 2, 2 -> 0, 2 -> 3, 3 -> 3 
Output: DFS from vertex 1 : 1 2 0 3

Iterative Depth First Traversal of Graph: https://www.geeksforgeeks.org/iterative-depth-first-traversal/