Data Structures & AlgorithmsHardGATE CS (PYQ pattern)

A DAG on vertices 1..6 has edges 1→3, 2→3, 3→4, 3→5, 2→6 and 5→6. How many distinct topological orderings does it have?

  1. A. 8
  2. B. 5
  3. C. 6
  4. D. 4

Correct answer: C. 6

Vertices 1 and 2 must precede 3 (2 orders), then 3 precedes 4 and 5, and 5 precedes 6, with 2 also before 6. Enumerating all linear extensions gives 6 valid orderings.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic