Data Structures & AlgorithmsHardGATE CS · Product-company placement

A DAG on vertices A–G has edges B→A, B→D, B→F, E→C, F→A, F→E, G→A, G→C. What order does Kahn's algorithm that always removes the alphabetically LARGEST vertex of in-degree 0 produce?

  1. A. B D F E G A C
  2. B. B G D F A E C
  3. C. G B F E C D A
  4. D. G B F E D C A

Correct answer: D. G B F E D C A

All four candidate orders are valid topological orders, which is exactly the trap: only the stated rule fixes one. Simulating it gives G B F E D C A.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic