Data Structures & AlgorithmsHardProduct-company placement

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

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

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

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic