Data Structures & AlgorithmsModerateInfosys · Graphs

A DAG has edges A->C, A->D, B->D, C->E, D->E, D->F, E->G, F->G. Using Kahn's algorithm and always removing the alphabetically smallest vertex with in-degree 0, what is the topological order produced?

  1. A. ABCDFEG
  2. B. ACBDEFG
  3. C. BADCEFG
  4. D. ABCDEFG

Correct answer: D. ABCDEFG

A and B start with in-degree 0 (A first), then B, then C, D, E, F and G become available in that order.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic