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

A DAG has edges A→B, A→C, B→D, C→E, A→D, B→C. 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. DBECA
  2. B. EDCBA
  3. C. ABCDE
  4. D. ACBDE

Correct answer: C. 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