Data Structures & AlgorithmsHardGATE CS · Product-company placement
How many topological orderings does the DAG on vertices A–F with edges C→F, D→A, D→F, E→A, F→A, F→B, F→E have?
- A. 5
- B. 8
- C. 6
- D. 12
Correct answer: C. 6
Count by placing vertices one at a time, each time choosing any vertex whose predecessors are all placed (or DP over subsets of placed vertices): 6 orderings in total.
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
- A tree on vertices 1–10 has edges 2–1, 3–1, 4–2, 5–2, 6–4, 7–6, 8–3, 9–7, 10–8. What is the size of a minimum DOMINATING set (every vertex…
- What is the length of the longest BITONIC subsequence (strictly increasing then strictly decreasing; either part may be empty) of [13, 15…
- Unit-time jobs (deadline, profit): J1 (2, 63), J2 (1, 38), J3 (2, 38), J4 (4, 52), J5 (2, 86), J6 (1, 75), J7 (1, 40). One job runs at a…
- A rooted tree has 7 nodes with 1 child, 2 nodes with 2 children, 4 nodes with 3 children, 8 nodes with 4 children, and every other node is…
- In how many ways can a convex polygon with 7 vertices be divided into triangles by non-crossing diagonals?
- Coins of denominations 1, 2, 8, 10 are available in unlimited supply. What is the minimum number of coins needed to make 16, and how many…