GATE Computer ScienceVery hardGATE CS (PYQ pattern)
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 optimal solution?
- A. 24
- B. 31
- C. 35
- D. 28
Correct answer: D. 28
Computing the optimal coin count by DP and the greedy count for every amount from 1 to 100 shows the two differ for 28 amounts (the first being 15: greedy uses 12 + 1 + 1 + 1 = 4 coins against 5 + 5 + 5 = 3 coins). The denomination 12 breaks the canonical property, so failures recur.
More Algorithms questions
- 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?
- How many DIFFERENT non-empty strings occur as subsequences of BANANAB (subsequences need not be contiguous; equal strings from different…