Data Structures & AlgorithmsHardGATE CS
Coins of denominations 1, 6, 9, 10 are available in unlimited supply. What is the minimum number of coins needed to make 33, and how many coins does the 'largest coin first' greedy method use?
- A. Minimum 6, greedy 6
- B. Minimum 4, greedy 6
- C. Minimum 4, greedy 4
- D. Minimum 3, greedy 6
Correct answer: B. Minimum 4, greedy 6
DP: best[a] = 1 + min best[a − c] gives 4; greedy takes the largest coin each time and needs 6. 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
- For the string BBABCBCAB, what are the lengths of the longest palindromic SUBSTRING and the longest palindromic SUBSEQUENCE?
- With 3 identical eggs and at most 5 drops, what is the largest number of floors for which you can always determine the critical floor (the…
- A complete binary tree (array form, all levels full except possibly the last, which is filled from the left) has 187 nodes. How many…
- The directed graph A→C (4), A→E (5), B→A (6), C→B (8), D→C (1), E→B (9), E→C (-6), E→D (2) has one negative edge but no negative cycle…
- Prim's algorithm starts at F on the weighted undirected graph A–C (28), A–D (6), A–F (3), A–G (7), B–C (14), B–F (26), C–D (21), C–E (19)…
- How many topological orderings does the DAG on vertices A–F with edges C→F, D→A, D→F, E→A, F→A, F→B, F→E have?