Data Structures & AlgorithmsHardProduct-company placement
How many subsets of {1, 6, 7, 8, 11, 13, 14} have sum exactly 28?
- A. 63
- B. 4
- C. 6
- D. 5
Correct answer: D. 5
dp[s] counts subsets with sum s; for each element update s from HIGH to low so it is used at most once, giving 5. Updating low to high lets an element be reused and gives 63.
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 DAG on vertices A–G has edges A→C, A→E, A→G, D→C, E→B, F→A, F→E, F→G. What order does Kahn's algorithm with a FIFO queue (initial zero…
- A complete binary tree (array form, all levels full except possibly the last, which is filled from the left) has 139 nodes. How many…
- A binary tree with distinct labels has INORDER E G A D B H C F I and LEVEL-ORDER D E I A F G H B C. What is its postorder traversal?
- A tree on vertices 1–11 has edges 2–1, 3–2, 4–1, 5–2, 6–3, 7–4, 8–6, 9–8, 10–8, 11–8. What is the size of a maximum independent set (no…
- A 4 × 4 grid has rows 6 6 6 4 / 7 6 5 2 / 2 9 8 2 / 5 1 8 9. Moving only right or down from the top-left to the bottom-right cell, what is…
- Bellman–Ford runs from A on the directed graph whose edges are relaxed in EVERY pass in this fixed order: F→A (9), D→A (4), E→D (8), C→B…