Challenge: Implement Depth-First Graph Traversal
Implement depth first graph traversal
We'll cover the following
Problem statement
You have to implement the depth-first traversal in Python.
To solve this problem, the previously implemented graph class is already prepended.
Input
A graph represented as an adjacency list and a starting vertex
Output
A string containing the vertices of the graph listed in the correct order of traversal
Sample input
Graph:
Vertex | Edges |
---|---|
0 | 2, 1 |
1 | 4, 3 |
2 | None |
3 | None |
4 | None |
Source: 0
Sample output
result = "01342"
or
result = "02143"
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.