Data Structures & AlgorithmsHardProduct-company placement

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

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

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic