Data Structures & AlgorithmsHardGATE CS · Product-company placement
How many subsets of {1, 4, 8, 9, 10, 11, 12} have sum exactly 27?
- A. 3
- B. 73
- C. 2
- D. 4
Correct answer: A. 3
dp[s] counts subsets with sum s; for each element update s from HIGH to low so it is used at most once, giving 3. Updating low to high lets an element be reused and gives 73.
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
- What is the maximum flow from S to T in the network with directed capacities A→B (15), A→C (9), A→T (12), B→T (12), C→B (12), S→A (6), S→B…
- An undirected graph has edges A–B, A–D, B–H, C–D, C–F, C–G, D–G, E–F, E–H, F–G. BFS starts at A and always scans neighbours in…
- A binary tree with distinct labels has INORDER G D C I F A B H E and LEVEL-ORDER E A D H G I B C F. What is its postorder traversal?
- An undirected graph has edges A–D, B–D, B–F, C–D, C–E, D–G, E–F, E–H, F–G, G–H. BFS starts at A and always scans neighbours in…
- An undirected graph has edges A–C, A–E, B–D, B–E, C–D, C–F, D–G, E–F, E–G. An ITERATIVE DFS starts with stack [A]; it pops a vertex, skips…
- An undirected graph has edges A–B, A–E, A–F, B–D, B–E, B–F, C–D, C–G, E–G. An ITERATIVE DFS starts with stack [A]; it pops a vertex, skips…