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?
- A. 4
- B. 1
- C. 6
- 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.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- How many structurally different binary search trees can be built from 4 distinct keys?
- Using the master theorem, what is the solution of T(n) = 4T(n/2) + n²?
- What is the solution of T(n) = T(n/3) + T(2n/3) + n?
- What is the length of the longest common subsequence of ALGORITHM and LOGARITHM?
- What is the edit distance (insert, delete, replace, each cost 1) between FLASK and FLOSSY?
- In how many ways can 10 be made from coins of 2, 3 and 5 (unlimited supply, order does not matter)?