Challenge: Implement Depth First Search
We will now tackle the implementation for Depth First Search.
We'll cover the following
Problem Statement
You have to implement the Depth First Search algorithm on a graph.
Note: Your solution should work for both connected and unconnected graphs.
Input
A graph in the form of an adjacency list
Note: You can start the traversal from any vertex.
Output
A string containing the vertices of the graph listed in the correct order of traversal.
Sample Input
Graph:
Vertex | Edges |
---|---|
1 | 3, 2 |
2 | 5, 4 |
3 | 6 |
4 | null |
5 | null |
6 | null |
Sample Output
"124536" or "136254"
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.