Question

Consider the following pseudocode for depth-first search (DFS) algorithm which takes a directed graph G(V,E)G(V, E) as input, where d[v]d[v] and 𝑓[v]𝑓[v] are the discovery time and finishing time, respectively, of the vertex v∈Vv \in V.

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 G(V,E)G(V, E) is a directed acyclic graph (DAG).

For an edge (u,v)∈E(u, v) \in E, which of the following options will NEVER be correct?

Choose every correct option
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 f[u]>f[v]f[u] > f[v] for every directed edge (u,v)∈E(u, v) \in E).

For any edge (u,v)∈E(u, v) \in E in a DAG:

  • Option (A) (d[u]<d[v]<f[v]<f[u]d[u] < d[v] < f[v] < f[u]) occurs whenever (u,v)(u, v) is a tree edge or forward edge.
  • Option (B) (d[v]<d[u]<f[u]<f[v]d[v] < d[u] < f[u] < f[v]) corresponds to (u,v)(u, v) being a back edge (where vv is an ancestor of uu in the DFS forest), which would form a directed cycle and can NEVER occur in a DAG.
  • Option (C) (d[v]<f[v]<d[u]<f[u]d[v] < f[v] < d[u] < f[u]) occurs whenever (u,v)(u, v) is a cross edge.
  • Option (D) (d[u]<d[v]<f[u]<f[v]d[u] < d[v] < f[u] < f[v]) violates the Parenthesis Theorem (discovery/finishing intervals [d[u],f[u]][d[u], f[u]] and [d[v],f[v]][d[v], f[v]] can never partially overlap) and can NEVER occur in any DFS.

Thus Options (B) and (D) will never be correct.

Final answer

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.