Breadth First Search
Breadth First Search
BFS(AdjacencyList:ListType , v:Integer)
Q: QUEUE;
Initialize Q to Empty;
Visit and mark v;
Insert v into Q; {Add to tail of Q}
while Q is not Empty do
x := Remove(Q); {Remove head of Q}
for each unmarked vertex w adjacent to x do
visit and mark w;
insert w into Q;
endfor
endwhile
end BFS