Depth-first search: Difference between revisions

From Algowiki
Jump to navigation Jump to search
m (Luedecke moved page Depth First Search to Depth-First Search)
No edit summary
Line 1: Line 1:
[[Category:Algorithms]]
[[Category:Search Algorithms]]
[[Category:Tree Algorithms]]
== Definition ==
== Definition ==



Revision as of 17:41, 10 September 2014

Definition

Pseudocode

DFS(G)

for each vertex uV [G]
do color[u] ← WHITE
π[u] ← NIL
time ← 0
do if color[u] == WHITE
then DFS-VISiT(u)


DFS-VISIT(u)

color[u] ← GRAY
timetime + 1
d[u] ← time
for each vAdj[u]
do if color[v] = WHITE
then π [v] ← u
DFS-VISIT(v)
color[u] ← BLACK
f[u] ← timetime + 1