DFS(G=<V,E>)DFS-VISIT(u)
- for each vertex u ∈ V do
- color[u] ← white
- π[u] ← NULL
- time ← 0
- for each vertex u ∈ V do
- if color[u] = white
- DFS-VISIT(u)
- color[u] ← gray
- time ← time + 1
- d[u] ← time
- for each vertex v ∈ Adj(u) do
- if color[u] = white
- π[v] = u
- DFS-VISIT(v)
- color[u] ← black
- f[u] ← time ← time + 1
BFS(G,s)
- for each vertex u ∈ V - {s} do
- color[u] ← white
- d[u] ← ∞
- π[u] ← NULL
- color[s] ← gray
- d[s] ← 0
- π[s] ← NULL
- Q ← Ø
- Q.Enqueue(s)
- while Q ≠ Ø do
- u ← Q.Dequeue()
- for each v ∈ adj(u) do
- if color[v] = white
- color[v] ← gray
- d[v] ← d[u] + 1
- π[v] = u
- Q.Enqueue(v)
- color[u] ← black