Challenge: Implement Breadth-First Graph Traversal

Implement breadth-first graph traversal

Problem statement

You have to implement the breadth-first traversal in Python.

To solve this problem, the previously implemented Graph class is already prepended.


A graph represented as an adjacency list and a starting vertex


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

Sample input


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

Source: 0

Sample output

result = "02143" 
result = "01234"

Traversal strategy: print the right child first and then, the left child.

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy