Data Structures & AlgorithmsVery hardGATE CS · TCS NQT · Product Company SDE

A DAG has edges A→B, A→C, A→D, A→E, D→E. Using Kahn's algorithm (always picking the smallest-labelled vertex among those currently available with in-degree 0), what is the topological order?

  1. A. ABCDE
  2. B. DBAEC
  3. C. EDCBA
  4. D. ACBDE

Correct answer: A. ABCDE

Repeatedly remove the smallest-labelled vertex with in-degree 0 and decrement its neighbours' in-degree, giving ABCDE.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic