By Anirudh C V
We traverse the graph by Breadth First Search , find neighbours of each node and shortest distance of a node from its root node
Breadth First Search (BFS) algorithm traverses a graph in a breadthward motion and uses a queue to remember to get the next vertex to start a search, when a dead end occurs in any iteration.
steps:
1.First move horizontally and visit all the nodes of the current layer.
2.Move to the next layer
3.Repeat the step 1 and step 2 until all nodes are covered (only once).
Here we also find neighbours of each node and the shortest distance of a node from its root node.
Submitted by Anirudh C V (AnirudhCV)
Download packets of source code on Coders Packet
Comments