Challenge 1: Implement Breadth First Search

Now, you will build the BFS algorithm in C# code.

Problem statement

You have to implement the Breadth First Search traversal in C#. You have already covered the logic behind this algorithm. All that is left to do is to flesh it out in code.

Note: Your solution should work for both connected and unconnected graphs.

To solve this problem, you will have all the previously implemented data structures available.

Input

The input is a graph in the form of an adjacency list.

Note: You can start the traversal from any vertex.

Output

The output is a string containing the vertices of the graph listed in the correct order of traversal.

Sample input

Graph:

Vertex Edges
0 None
1 3, 2
2 5, 4
3 None
4 None
5 None

Sample output

"013254"

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