Question
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): Explore(G, v, t):
unmark all v in V mark v
t <- 0 t <- t + 1
for each v in V d[v] <- t
if v is unmarked for each (v, w) in E
t <- Explore(G, v, t) if w is unmarked
end if t <- Explore(G, w, t)
end for end if
end for
t <- t + 1
f[v] <- t
return t
Suppose that the input directed graph is a directed acyclic graph (DAG).
For an edge , which of the following options will NEVER be correct?
Official answer and solution
- Official answer
- B and D
- From
- Official GATE 2026 answer key
Solution
Use the DFS Parenthesis Theorem and the fact that a DAG has no back edges (so for every directed edge ).
For any edge in a DAG:
- Option (A) () occurs whenever is a tree edge or forward edge.
- Option (B) () corresponds to being a back edge (where is an ancestor of in the DFS forest), which would form a directed cycle and can NEVER occur in a DAG.
- Option (C) () occurs whenever is a cross edge.
- Option (D) () violates the Parenthesis Theorem (discovery/finishing intervals and can never partially overlap) and can NEVER occur in any DFS.
Thus Options (B) and (D) will never be correct.
Options (B), (D)
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2026 Computer Science and Information Technology - Session 1 (CS1)
- Question
- 50 of 65
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.