Your question is Breadth-First Search. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Implement breadth-first search on a graph and return the order in which nodes are visited starting from a given node.
The graph is represented as an adjacency list: a dictionary where each key is a node and its value is a list of neighboring nodes. Visit neighbors in the order they appear in the list. If the start node is not in the graph, return an empty list.
Write a function bfs(graph, start) that returns a list of nodes in BFS visitation order.
graph: dict mapping each node to a list of adjacent nodesstart: the starting nodelist of nodes visited in BFS orderUse a queue for traversal and avoid visiting the same node more than once.
def bfs(graph, start):