Java: Iterative Depth First Traversal of Graph

Level : Intermediate
Mentor: Shailendra Chauhan
Type : GuidedLab
Points : 10
Duration : 00:30:00

Lab Details

Problem Statement:

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.

Write a program to implement Depth first Traversal iteratively.

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
Self-paced Membership
  • 24+ Video Courses
  • 825+ Hands-On Labs
  • 400+ Quick Notes
  • 125+ Skill Tests
  • 10+ Interview Q&A Courses
  • 10+ Real-world Projects
  • Career Coaching Sessions
  • Email Support
Upto 60% OFF
Know More
Still have some questions? Let's discuss.
CONTACT US
Accept cookies & close this