GATE Computer ScienceHardGATE CS (PYQ pattern)
A 0/1 knapsack has capacity 26 and items (weight, value): (12, 24), (7, 13), (11, 23), (8, 15), (9, 16), (6, 11). The maximum total value is:
- A. 47
- B. 52
- C. 51
- D. 49
Correct answer: C. 51
DP over capacity gives 51, achieved by items (7, 13), (8, 15) and (11, 23) of total weight 26. Greedy by value/weight ratio picks (11, 23) and (12, 24), reaching only 47, and the fractional optimum 52.6 is just an upper bound.
More Algorithms questions
- A coin system has denominations {1, 5, 10, 20, 25}. The greedy algorithm (always take the largest coin that fits) first gives a…
- 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: