Data Structures & AlgorithmsHardGATE CS · Product-company placement

A DAG on vertices A–G has edges A→D, A→F, C→D, E→C, F→B, F→D, G→A, G→F. 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. E G C A F B D
  2. B. E C G A F B D
  3. C. G E C A F D B
  4. D. G E C A F B D

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

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic