Challenge: Implement Depth-First Graph Traversal

Implement depth-first traversal with an adjacency list.

Problem statement

Implement the depth-first traversal in C#. It is a searching algorithm for the graph that traverses down each branch depth-wise and backtracks after reaching a leaf node. We will use our already-implemented Graph class for this task (since we have already covered the implementation of graphs).

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.

Output

A string containing the vertices of the graph listed in the correct order of traversal.

Sample input

Graph:

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.