Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2 B

A directed acyclic graph has the vertices E, N, O, S, U, V, Z and the edges Z→S, N→O, U→V, U→N, U→O, E→V, E→S. A topological order lists every vertex once so that each edge goes from an earlier to a later vertex. Which topological order is lexicographically smallest when read as a sequence of letters?

  1. A. Z U N O E V S
  2. B. E U N O V Z S
  3. C. Z U E V N O S
  4. D. Z U E N V O S

Correct answer: B. E U N O V Z S

Kahn's algorithm that always takes the smallest available vertex (a min-heap) gives E U N O V Z S. A FIFO queue gives E U Z N V S O, which can differ, and a reverse-postorder DFS gives Z U N O E V S.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic