Data Structures & AlgorithmsHardProduct-company placement
Coins of denominations 1, 3, 6, 8 are available in unlimited supply. What is the minimum number of coins needed to make 28, and how many coins does the 'largest coin first' greedy method use?
- A. Minimum 4, greedy 5
- B. Minimum 5, greedy 5
- C. Minimum 4, greedy 4
- D. Minimum 3, greedy 5
Correct answer: A. Minimum 4, greedy 5
DP: best[a] = 1 + min best[a − c] gives 4; greedy takes the largest coin each time and needs 5. This coin system is not canonical, so greedy fails.
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 length of the shortest string that has BOTH INTERVAL and RECESSION as subsequences (shortest common supersequence)?
- A tree on vertices 1–8 has edges 2–1, 3–1, 4–2, 5–4, 6–5, 7–2, 8–7. What is the sum of the distances (in edges) over all unordered pairs…
- How many structurally different binary trees with 7 nodes have height EXACTLY 3 (height = edges on the longest root-to-leaf path)?
- How many calls of g (including the first) are made when g(8) is evaluated, and what value is returned? c int g(int n) { if (n <= 2) return…
- A tree on vertices 1–11 has edges 2–1, 3–1, 4–1, 5–3, 6–3, 7–6, 8–5, 9–6, 10–9, 11–9. What is the size of a maximum independent set (no…
- Keys 88, 38, 16, 75, 87, 68, 51, 36, 82, 61 are inserted in order into an empty AVL tree. Counting a double rotation as two single…