Created
April 1, 2019 14:13
-
-
Save Ashaba/d0a95ee97fa8b4890fae1e5e9a34a43f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BFS (G, s) //Where G is the graph and s is the source node | |
let Q be queue. | |
Q.enqueue( s ) //Inserting s in queue until all its neighbour vertices are marked. | |
mark s as traversed. | |
while ( Q is not empty) | |
//Removing that vertex from queue,whose neighbour will be visited now | |
v = Q.dequeue( ) | |
//processing all the neighbours of v | |
for all neighbours w of v in Graph G | |
if w is not visited | |
Q.enqueue( w ) //Stores w in Q to further visit its neighbour | |
mark w as visited. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment