Challenge 2: Implement Depth First Graph Traversal
Given a graph, print its depth-first graph traversal.
We'll cover the following
Problem Statement
Implement the Depth-First Traversal in C++.
To solve this problem, all the previously implemented data structures will be available to us.
Input
A graph represented as an adjacency list
and a starting vertex (root).
Output
A string containing the vertices of the graph listed in the correct order of traversal.
Sample Input
Graph:
graph = {0 -> 1
1 -> 2
1 -> 3
2 -> 4
3 -> 4
3 -> 5}
Sample Output
"0 1 2 4 3 5" or "0 1 2 4 3 5"
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.