GateAI
Graph Traversals

GATE CSE 2026 Set 1 · Q50

MSQ2 marksMedium

Time

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. 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?

GATE CSE 2026 Set 1 Q50 diagram

Select all that applyOne or more correct

Pick every correct option

Solution

Step-by-step verified solution

Official answer: B) d[v] < d[u] < f[u] < f[v]; D) d[u] < d[v] < f[u] < f[v]

Graph Traversals

By the Parenthesis Theorem of Depth-First Search (DFS), for any two vertices uu and vv, the intervals [d[u],f[u]][d[u], f[u]] and [d[v],f[v]][d[v], f[v]] are either completely disjoint or one is strictly nested within the other.

Let us analyze the possible relationships for an edge (u,v)∈E(u, v) \in E in a Directed Acyclic Graph (DAG):

  1. Option A: d[u]<d[v]<f[v]<f[u]d[u] < d[v] < f[v] < f[u]

    • This represents [d[v],f[v]]⊂[d[u],f[u]][d[v], f[v]] \subset [d[u], f[u]], meaning vv is a descendant of uu in the DFS tree. This occurs when (u,v)(u, v) is a tree edge or a forward edge.

    • Hence, this case can occur.

  2. Option B: d[v]<d[u]<f[u]<f[v]d[v] < d[u] < f[u] < f[v]

    • This represents [d[u],f[u]]⊂[d[v],f[v]][d[u], f[u]] \subset [d[v], f[v]], meaning uu is a descendant of vv in the DFS forest, which makes (u,v)(u, v) a back edge.

    • A directed graph is a DAG if and only if a DFS yields no back edges.

    • Hence, this case can NEVER be correct for a DAG.

  3. Option C: d[v]<f[v]<d[u]<f[u]d[v] < f[v] < d[u] < f[u]

    • This represents two disjoint intervals where vertex vv was discovered and finished before vertex uu was discovered. This occurs when (u,v)(u, v) is a cross edge (e.g., when the DFS explores the subtree containing vv before exploring uu).

    • Hence, this case can occur.

  4. Option D: d[u]<d[v]<f[u]<f[v]d[u] < d[v] < f[u] < f[v]

    • This represents partially overlapping intervals, which is strictly prohibited by the Parenthesis Theorem for any DFS traversal.

    • Hence, this case can NEVER be correct.

Therefore, options B and D will NEVER be correct.

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Graph Traversals previous year question is Q50 of the GATE CSE 2026 Set 1 paper. Find more GATE CSE PYQs on Graph Traversals in Algorithms, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Graph Traversals PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Graph Traversals in GATE CSE

Graph Traversals has 16 GATE CSE PYQs across 12 papers from 2014 to 2026. 5 of them are 2-mark MSQs like this one, and GATE CSE 2026 Set 1 has 2.

How GATE tests Graph Traversals

More from GATE CSE 2026 Set 1

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2026 Set 1 · Q50 · MSQ

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 ∈ V. Suppose that the input directed graph G(V, E) is a directed acyclic graph (DAG). For an edge (u, v) ∈ E, which of the following options will NEVER be correct?

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.