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?
- A. 5
- B. 4
- C. 6
- 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.
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
- Prim's algorithm starts at A on the undirected graph with edges A–B (3), A–C (1), B–C (7), B–D (5), C–D (2), C–E (7), D–E (3), D–F (8)…
- An undirected graph on A, B, C, D has edges A–B, B–C, C–D, D–A of weight 1 and a diagonal A–C of weight 2. How many distinct minimum…
- Union-find on elements 0–7 uses union by size (the smaller tree's root points to the larger tree's root; on a tie the second root points…
- Seven distinct keys are stored in a max-heap in a 0-indexed array. Which statement is correct?
- How many of these statements are correct? (i) Building a heap from n elements by bottom-up sift-down takes O(n) time. (ii) Inserting n…
- How many different max-heaps (as arrays) can be formed from 5 distinct keys?