GATE Computer ScienceEasyGATE CS (PYQ pattern)
A coin system has denominations {1, 5, 10, 20, 25}. The greedy algorithm (always take the largest coin that fits) first gives a non-minimum number of coins for which smallest amount?
- A. 40
- B. 30
- C. 35
- D. 45
Correct answer: A. 40
For 40 greedy picks 25 + 10 + 5 (3 coins) while 20 + 20 uses 2. Amounts 30 (25 + 5) and 35 (25 + 10) are optimal, and a check of every smaller amount confirms 40 is the first failure.
More Algorithms questions
- For the coin system {1, 5, 12, 25}, among the amounts 1, 2, …, 100, for how many amounts does the greedy algorithm use more coins than the…
- Using unlimited coins of denominations 2, 5, 7 and 10 (order does not matter), how many ways are there to pay exactly 40 using at most 6…
- In the array [2, 5, 3, 7, 11, 8, 10, 13, 6, 9, 4, 12] the longest strictly increasing subsequences have length 6. How many different…
- The O(n log n) LIS algorithm keeps an array t where t[k] is the smallest tail of an increasing subsequence of length k + 1; each element x…
- The longest palindromic subsequence of the string BCABDACBDCA has length:
- What is the minimum number of cuts needed to partition the string abacbbcabbacab into substrings that are all palindromes?