Data Structures & AlgorithmsModerateIBM · Deloitte pattern

A DAG has edges A→B, A→C, B→D, C→D, D→E. How many different topological orderings does it have?

  1. A. 4
  2. B. 1
  3. C. 6
  4. D. 2

Correct answer: D. 2

A must come first and D, E last (in that order); only B and C are free and can go either way: A B C D E or A C B D E. Any vertex order without counting the constraints would give 120.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic