bfs sudocode

Solutions on MaxInterview for bfs sudocode by the best coders in the world

showing results for - "bfs sudocode"
Mirielle
12 Nov 2018
1BFS (G, s)                   //Where G is the graph and s is the source node
2      let Q be queue.
3      Q.enqueue( s ) //Inserting s in queue until all its neighbour vertices are marked.
4
5      mark s as visited.
6      while ( Q is not empty)
7           //Removing that vertex from queue,whose neighbour will be visited now
8           v  =  Q.dequeue( )
9
10          //processing all the neighbours of v  
11          for all neighbours w of v in Graph G
12               if w is not visited 
13                        Q.enqueue( w )             //Stores w in Q to further visit its neighbour
14                        mark w as visited.
similar questions
queries leading to this page
bfs sudocode