Depth-first search: Difference between revisions
Jump to navigation
Jump to search
Line 7: | Line 7: | ||
==== DFS(''G'') ==== | ==== DFS(''G'') ==== | ||
: | :'''for''' each vertex ''u'' ∈ ''V'' [''G''] | ||
:: | ::'''do''' color['''u'''] ← WHITE | ||
::: ''π''[''u''] ← NIL | |||
:''time'' ← 0 | |||
:: '''do if''' ''color''[''u''] == WHITE | |||
::: '''then''' DFS-VISiT(''u'') | |||
====DFS-VISIT(''u'')==== | |||
: ''color''[''u''] ← GRAY | |||
: ''time'' ← ''time'' + 1 | |||
: ''d''[''u''] ← ''time'' | |||
: '''for''' each ''v'' ∈ ''Adj''[''u''] |
Revision as of 17:03, 14 August 2014
Definition
Pseudocode
DFS(G)
- for each vertex u ∈ V [G]
- do color[u] ← WHITE
- π[u] ← NIL
- do color[u] ← WHITE
- time ← 0
- do if color[u] == WHITE
- then DFS-VISiT(u)
- do if color[u] == WHITE
DFS-VISIT(u)
- color[u] ← GRAY
- time ← time + 1
- d[u] ← time
- for each v ∈ Adj[u]