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

A DAG has edges A→B, B→C, B→D, C→E, A→F, A→D, D→F. 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. ABCDEF
  2. B. FEDCBA
  3. C. EBDFAC
  4. D. ACBDEF

Correct answer: A. ABCDEF

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic