Skip to main content

GATE CSE 2007Algorithms › Graph AlgorithmsVerified

GATE CSE 2007 PYQ: Consider the DAG with V = { 1 , 2 , 3 , 4 , 5 , 6 } V = \{1,2,3,4,5,6\} V = { 1 , 2 , 3 , 4 , 5 , 6 } shown…

Consider the DAG with V={1,2,3,4,5,6}V = \{1,2,3,4,5,6\} shown below.

GATE CSE 2007 Graph Algorithms diagram: Consider the DAG with V = { 1 , 2 , 3 , 4 , 5 , 6 } V = \{1,

Which of the following is not a topological ordering?

  1. A
    1 2 3 4 5 6
  2. B
    1 3 2 4 5 6
  3. C
    1 3 2 4 6 5
  4. D
    3 2 4 1 6 5
    Correct answer

Answer

(D) 3 3 3 2 2 2 4 4 4 1 1 1 6 6 6 5 5 5

Approach

A topological ordering of a DAG must list every vertex so that for each directed edge $u \to v$, vertex $u$ appears before vertex $v$. Extract the precedence constraints implied by the graph's edges, then test each of the four sequences against those constraints. The sequence that breaks at least one precedence rule is the one that is NOT a topological ordering.

The graph enforces the precedences $1\prec\{2,3\}$, $\{2,3\}\prec4$, and $4\prec\{5,6\}$. Options A, B and C all respect these constraints. Option D begins with 3 and places 4 and 1 after it, directly violating the edges $1\to3$ and $1\to4$; therefore D is the only sequence that is not a topological ordering.

Reviewed by GateIQ Editorial Team: IIT & IISc Alumni.