Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save lyaotian/5801382 to your computer and use it in GitHub Desktop.
Depth-first Search
procedure DFS(G,v):
label v as explored
for all edges e in G.adjacentEdges(v) do
if edge e is unexplored then
w ← G.adjacentVertex(v,e)
if vertex w is unexplored then
label e as a discovery edge
recursively call DFS(G,w)
else
label e as a back edge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment