Consider the DAG with shown below.
Which of the following is not a topological ordering?
GATE CSE 2007Algorithms › Graph AlgorithmsVerified
(D) 3 3 3 2 2 2 4 4 4 1 1 1 6 6 6 5 5 5
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.