Skip to content

Instantly share code, notes, and snippets.

@lyaotian
Created June 17, 2013 23:17
Show Gist options
  • Select an option

  • Save lyaotian/5801368 to your computer and use it in GitHub Desktop.

Select an option

Save lyaotian/5801368 to your computer and use it in GitHub Desktop.
Breadth-first Search
procedure BFS(G,v):
create a queue Q
enqueue v onto Q
mark v
while Q is not empty:
t ← Q.dequeue()
if t is what we are looking for:
return t
for all edges e in G.adjacentEdges(t) do
o ← G.adjacentVertex(t,e)
if o is not marked:
mark o
enqueue o onto Q
return nul
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment