GATE / CS ARCHIVE

GATE CSE 2026 SET 1 / QUESTION 50

DFS time intervals on a DAG

Algorithms · Graph Algorithms · Full GATE CSE 2026 Set 1 paper

GATE 2026 Set 1, Q50 2 marks · MSQ
Report issue

Graph Algorithms

Question 50, GATE 2026: DFS assigns each vertex discovery time d and finish time f. The directed input graph is acyclic. For an edge u→v, which time orders are impossible? A d[u]<d[v]<f[v]<f[u]; B d[v]<d[u]<f[u]<f[v]; C d[v]<f[v]<d[u]<f[u]; D d[u]<d[v]<f[u]<f[v].
Tap to enlarge
Select all that apply
Answer & solution

Official answer: B, D

Givens and goal

DFS assigns each vertex discovery time d and finish time f. The directed input graph is acyclic. For an edge u→v, which time orders are impossible? A d[u]<d[v]<f[v]<f[u]; B d[v]<d[u]<f[u]<f[v]; C d[v]<f[v]<d[u]<f[u]; D d[u]<d[v]<f[u]<f[v].

Approach

Use the parenthesis theorem for recursive DFS intervals, then use acyclicity to exclude ancestor-directed back edges.

Step-by-step solution

1. A DFS call remains active while all recursive descendants are explored. Therefore two vertices’ discovery-to-finish intervals are either nested, for an ancestor and descendant, or disjoint. Partial overlap is impossible.
2. D has d[u]<d[v]<f[u]<f[v], a partial overlap. Once v is discovered while u’s call is active, v must finish before that call can finish. Thus D is impossible in every DFS, regardless of whether the graph is acyclic.
3. In B, v’s interval strictly contains u’s, so v is a DFS ancestor of u. The DFS-tree edges give a directed path v→…→u. Together with the given edge u→v, this creates a directed cycle, forbidden in a DAG. Hence B is also impossible.
4. A is possible: take the graph with only edge u→v and begin at u. The times can be d[u]=1,d[v]=2,f[v]=3,f[u]=4, a tree-edge interval.
5. C is possible if v is explored first and finishes before u is discovered. With the same single edge u→v, choose v as the first DFS root: times can be d[v]=1,f[v]=2,d[u]=3,f[u]=4. The later edge goes to an already finished vertex and creates no cycle.
6. Select B and D. The DAG restriction is needed for excluding B; the nesting rule alone already excludes D.

Original paper, page 38 · Answer key