Skip to content

Beta · Data may be lost.Your data may be reset or lost.

GateBrew
← GATE CSE 2026 Set 1
Questions

Q40

MSQ2 marksAlgorithms

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 f[v]f[v] are the discovery time and finishing time, respectively, of the vertex v∈Vv \in V.

DFS(G):unmark all v∈Vt←0for each v∈Vif v is unmarkedt←Explore(G,v,t)end ifend forExplore(G,v,t):mark vt←t+1d[v]←tfor each (v,w)∈Eif w is unmarkedt←Explore(G,w,t)end ifend fort←t+1f[v]←treturn t\def\arraystretch{1.3} \begin{array}{l|l} \hline \textbf{DFS}(G): \begin{array}{l} \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} & \textbf{Explore}(G,v,t): \begin{array}{l} \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)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?

Sign in to save attempts.

The solution is hidden while you attempt this question. It opens once you check or show the answer.