Created
March 16, 2018 05:31
-
-
Save NavneetPrakashSingh/58ac20bba19bcf3b6f640ef6aed755cc to your computer and use it in GitHub Desktop.
Breadth-first search
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) | |
for each vertex in graph (u) except source vertex (s) | |
u.color = white | |
u.d = infinte | |
u.a = nil | |
s.color = gray | |
s.d = 0 | |
s.a = nil | |
Q = 0 //create an empty queue | |
Enqueue(Q) | |
while Q!=null | |
u = Dequeue(Q) | |
for each v in adjacent[u] | |
if v.color = white | |
v.color = gray | |
v.d = v.d + 1 | |
v.a = u | |
Enqueue(Q,v) | |
u.color = Black |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment