Data Structures & AlgorithmsHardGATE CS

A DAG on vertices A–G has edges A→C, A→E, A→G, D→C, E→B, F→A, F→E, F→G. What order does Kahn's algorithm with a FIFO queue (initial zero in-degree vertices enqueued alphabetically; newly freed vertices enqueued in the order they become free, scanning each adjacency list alphabetically) produce?

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

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

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic