Data Structures & AlgorithmsHardProduct-company MCQ pattern

How many topological orderings does the DAG with edges A→B, A→C, B→D, C→D, D→E, B→F have?

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

Correct answer: D. 7

Ignoring F, the orders are A B C D E and A C B D E. F only has to come after B: in A B C D E it can go in 4 places (after B, C, D or E), and in A C B D E in 3 places, so 4 + 3 = 7. Forcing F before D or E by mistake gives fewer.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic