Data Structures & AlgorithmsHardProduct-company placement
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 coins does the 'largest coin first' greedy method use?
- A. Minimum 4, greedy 4
- B. Minimum 2, greedy 2
- C. Minimum 1, greedy 4
- D. Minimum 2, greedy 4
Correct answer: D. Minimum 2, greedy 4
DP: best[a] = 1 + min best[a − c] gives 2; greedy takes the largest coin each time and needs 4. 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
- Heap sort (ascending) is run on [3, 13, 29, 24, 7, 25, 19, 40]: build a max-heap bottom-up, then repeatedly swap the root with the last…
- Dijkstra's algorithm runs from A on the directed graph A→C (4), A→D (15), B→A (2), B→C (13), C→D (8), C→E (7), C→F (2), D→B (12), E→B (7)…
- Floyd–Warshall runs on vertices 1–4 with directed edges 1→2 (2), 1→3 (8), 2→1 (8), 2→4 (3), 3→2 (7), 3→4 (6), 4→1 (2). After the…
- A tree on vertices 1–9 has edges 2–1, 3–2, 4–2, 5–2, 6–5, 7–4, 8–5, 9–7. What are its diameter and radius, and which vertex/vertices form…
- An undirected graph has edges A–E, A–G, A–H, B–H, C–E, D–F, D–H, E–G, F–H, G–H. BFS starts at A and always scans neighbours in…
- Lectures occupy half-open intervals [start, end): [2, 7), [6, 11), [8, 14), [9, 14), [10, 16), [13, 16), [13, 20), [14, 20). A lecture…