Given below is an undirected graph in the format of an adjacency list:
A: [B, C]
B: [A, C, E]
C: [A, B, D, E]
D: [C, F, G]
E: [B, C, F]
F: [D, E, G]
G: [D, F]
Apply the BFS procedure using the node as the initial node and find the shortest distances to each node of the graph. Try not to draw the graph but use only the given representation. The expected output format is the following:
1 3 0 2 4
Here, is the shortest distance from the start node to , – the same for , and so on.
Hint: recall from the theory that in order to traverse the nodes in the increasing order of distance from the start node, you need to use the queue data structure.