Data Structures & AlgorithmsHardGATE CS · ICPC regional

Directed acyclic graph on vertices A, B, C, D, E with edges A→D, A→C, D→B, D→C. Among all topological orderings (every edge goes from earlier to later in the order), which one is lexicographically smallest when compared letter by letter? Give it as letters separated by spaces.

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

Correct answer: B. A D B C E

Kahn's algorithm with a min-heap always takes the smallest available vertex and yields A D B C E. A FIFO queue or reverse DFS postorder gives valid orders that are not lexicographically smallest.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic