GATE Computer ScienceHardGATE CS (PYQ pattern)

Kahn's topological sort uses a min-priority queue, so among available vertices the smallest label is always chosen. The DAG has edges 1→3, 2→3, 2→4, 3→5, 4→5, 6→2, 6→7, 7→4, 5→8, 1→8. Which vertex is the fifth in the output order?

  1. A. 7
  2. B. 3
  3. C. 4
  4. D. 5

Correct answer: A. 7

The output is 1, 6, 2, 3, 7, 4, 5, 8: vertex 7 only becomes available after 6, and the min-queue prefers 2 and 3 before 7. The fifth vertex is 7.

More Algorithms questions

Exams that ask this topic