BFS(G,s) 1 foreach v in (V - {s}) ; initialize 2 visited(v) = False 3 pred(v) = NIL 4 distance(v) = 5 visited(s) = True ; visit start vertex 6 distance(s) = 0 7 pred(s) = NIL 8 Enqueue(Q, s) 9 while not QueueEmpty(Q) 10 u = DeQueue(Q) 11 foreach v in Adj[u] 12 if not visited(v) 13 then visited(v) = True 14 distance(v) = distance(u) + 1 15 pred(v) = u 16 Enqueue(Q, v)