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
  • 22+ Courses
  • 750+ Hands-On Labs
  • 200+ Quick Notes
  • 55+ Skill Tests
  • 45+ Interview Q&A
  • 10+ Real-world Projects
  • Career Coaching
  • Email Support
Upto 66% OFF
KNOW MORE..

To get full access to all courses

Still have some questions? Let's discuss.
CONTACT US
Accept cookies & close this