DFS(G,s) For all v in V v.status = unexplored Endfor s.status = discovered s.parent = null DFSVisit(G,s) DFSVisit(G,v) For each u adjacent to v If u.status = unexplored u.status = discovered u.parent = v DFSVisit(u) EndIF EndFor v.status = finished
For each v in V If v.status = unexplored v.status = discovered v.parent = null DFSVisit(G,v) EndIf EndFor
DFS(G,s) // S is a stack For each v in V v.status = unexplored EndFor s.status = discovered s.parent = null S.push(s) While S is not empty v = S.Pop v.status = finished For each u adjacent to v if u.status = unexplored u.status = discovered u.parent = v S.push(u) EndFor EndWhile