Consider the following pseudocode for depth-first search (DFS) algorithm which takes a directed graph as input, where and are the discovery time and finishing time, respectively, of the vertex .
DFS(G):
unmark all v ∈ V
t ← 0
for each v ∈ V
if v is unmarked
t ← Explore(G, v, t)
end if
end forExplore(G, v, t):
mark v
t ← t + 1
d[v] ← t
for each (v, w) ∈ E
if w is unmarked
t ← Explore(G, w, t)
end if
end for
t ← t + 1
f[v] ← t
return tSuppose that the input directed graph is a directed acyclic graph (DAG).
For an edge , which of the following options will NEVER be correct?
Tap to open full sizeFigure description
Two side-by-side pseudocode blocks (not a diagram): the left block, DFS(G), unmarks all vertices, initializes t=0, and for each unmarked vertex calls Explore, updating t with the return value. The right block, Explore(G, v, t), marks v, increments t, sets d[v]=t, iterates over all out-edges (v,w) of v, recursively calling Explore(G,w,t) if w is unmarked (updating t), then after the loop increments t, sets f[v]=t, and returns t.
- (A)
- (B)
- (C)
- (D)