Color all nodes on the graph white
Color the start node grey
Put start node in the queue
While the queue is not empty
remove a node n from the queue
color n black
foreach child c of n
color c grey
parent of c = n
enqueue c
BFS(G,s), G=(V,E)
( 1) foreach vertex v in V-{s}
( 2) color(v) = whilte
( 3) depth(v) = inf
( 4) parent(v) = NULL
( 5) color(s) = grey
( 6) Q.Enqueue(s)
( 7) depth(s) = 0
( 8) parent(s) = NULL
( 9) while !Q.IsEmpty()
(10) u = Q.Front()
(11) foreach v adjacient(u)
(12) if (color(v) == white)
(13) color(v) = grey
(14) depth(v) = depth(v) + 1
(15) parent(v) = u
(16) Q.Enqueue(v)
(17) Dequeue(Q)
(18) color(u) = black;