GATE CS 2026 · Set-1 · Graph Traversals (BFS & DFS)

MSQ · 2 marks · Problem PROG-GRPH-0036

Consider the following pseudocode for depth-first search (DFS) algorithm which takes a directed graph \(G(V, E)\) as input, where \(d[v]\) and \(f[v]\) are the discovery time and finishing time, respectively, of the vertex \(v \in V\). \[\begin{array}{|l|l|} \hline \begin{array}{l} \textbf{DFS}(G): \\ \text{unmark all } v \in V \\ t \leftarrow 0 \\ \text{for each } v \in V \\ \quad \text{if } v \text{ is unmarked} \\ \qquad t \leftarrow \text{Explore}(G,v,t) \\ \quad \text{end if} \\ \text{end for} \end{array} & \begin{array}{l} \textbf{Explore}(G,v,t): \\ \text{mark } v \\ t \leftarrow t+1 \\ d[v] \leftarrow t \\ \text{for each } (v,w) \in E \\ \quad \text{if } w \text{ is unmarked} \\ \qquad t \leftarrow \text{Explore}(G,w,t) \\ \quad \text{end if} \\ \text{end for} \\ t \leftarrow t+1 \\ f[v] \leftarrow t \\ \text{return } t \end{array} \\ \hline \end{array}\]Suppose that the input directed graph \(G(V, E)\) is a directed acyclic graph (DAG). For an edge \((u, v) \in E\), which of the following options will NEVER be correct?
  1. A
    \(d[u] < d[v] < f[v] < f[u]\)
  2. B
    \(d[v] < d[u] < f[u]< f[v]\)
  3. C
    \(d[v] < f[v] < d[u] < f[u]\)
  4. D
    \(d[u] < d[v] < f[u] < f[v]\)

Solve it on GATE DA practice →More Graph Theory & Algorithms problems

Show the worked solutionOfficial GATE Answer Key: B, D.See full step-by-step discussion on GateOverflow: https://gateoverflow.in/523040/gate-cse-2026-set-1-question-40

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com