Data Structures & AlgorithmsHardGATE CS · Product-company placement
Coins of denominations 1, 9, 10, 11 are available in unlimited supply. What is the minimum number of coins needed to make 18, and how many coins does the 'largest coin first' greedy method use?
- A. Minimum 2, greedy 8
- B. Minimum 8, greedy 8
- C. Minimum 2, greedy 2
- D. Minimum 1, greedy 8
Correct answer: A. Minimum 2, greedy 8
DP: best[a] = 1 + min best[a − c] gives 2; greedy takes the largest coin each time and needs 8. 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
- A BST holds integer keys between 1 and 100. Which sequence CANNOT be the sequence of keys examined while searching for 46?
- Dijkstra's algorithm runs from A on the directed graph A→B (6), A→E (1), A→F (11), B→C (9), B→D (2), B→F (1), C→D (10), C→F (11), D→A (5)…
- With 3 identical eggs and at most 7 drops, what is the largest number of floors for which you can always determine the critical floor (the…
- 0/1 knapsack with capacity 18: items (weight, value) = (8, 39), (2, 16), (3, 24), (6, 38), (3, 36). What is the maximum total value?
- Six sorted files have 8, 23, 33, 38, 42, 49 records. Merging two files of sizes a and b costs a + b. What is the minimum total cost to…
- Kruskal's algorithm runs on the weighted undirected graph A–B (15), A–F (7), A–G (21), B–C (17), B–D (23), B–F (22), D–F (8), E–F (13)…