GATE CS 2026 Set 1 | Question 50

Algorithms › Graph Algorithms · MSQ · 2 marks · Answer: B, D

  1. Question 50Algorithmsmsq2 marks
    Consider the following pseudocode for depth-first search (DFS) algorithm which takes a directed graph as input, where and are the discovery time and finishing time, respectively, of the vertex .
    DFS(G):                          Explore(G, v, t):
      unmark all v ∈ V                 mark v
      t ← 0                            t ← t + 1
      for each v ∈ V                   d[v] ← t
        if v is unmarked               for each (v, w) ∈ 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 is a directed acyclic graph (DAG). For an edge , which of the following options will NEVER be correct?
    • A.
    • B.
      ✓
    • C.
    • D.
      ✓

    Answer: B, D

    Solution

    Answer: B, D Key fact: in a DAG, every edge satisfies . This is why reverse finishing order is a topological sort. • (A) Tree or forward edge: possible. • (B) is nested inside , so is a back edge, which means a cycle. Never. • (C) Cross edge to an already finished : possible. • (D) The intervals partly overlap, which the parenthesis theorem rules out for any DFS. Never.

More GATE PYQ on Graph Algorithms

All GATE CS Algorithms PYQ →

Attempt GATE CS 2026 Set 1 in real GATE exam mode

Full paper with a timer, the GATE interface and a topic-wise analysis — free.

Create free account →