Question
Consider the weights and values of items listed below. Note that there is only one unit of each item.
| Item number | Weight (in Kgs) | Value (in Rupees) |
|---|---|---|
| 1 | 10 | 60 |
| 2 | 7 | 28 |
| 3 | 4 | 20 |
| 4 | 2 | 24 |
The task is to pick a subset of these items such that their total weight is no more than 11 Kgs and their total value is maximized. Moreover, no item may be split. The total value of items picked by an optimal algorithm is denoted by . A greedy algorithm sorts the items by their value-to-weight ratios in descending order and packs them greedily, starting from the first item in the ordered list. The total value of items picked by the greedy algorithm is denoted by .
The value of is ____________.
Official answer and solution
- Official answer
- 16
- From
- Official GATE 2018 answer key
Solution
Compute the greedy selection based on value-to-weight ratios and compare it with the exact 0/1 knapsack optimum.
Compute value-to-weight ratios for all items:
- Item 1:
- Item 2:
- Item 3:
- Item 4:
Greedy packing (sorted by ratio descending: Item 4, Item 1, Item 3, Item 2):
- Pick Item 4: weight = 2, value = 24, capacity remaining = .
- Next is Item 1: weight = 10. Since , cannot pack Item 1.
- Next is Item 3: weight = 4. Since , pack Item 3: value becomes , capacity remaining = .
- Next is Item 2: weight = 7. Since , cannot pack Item 2.
Thus, .
Optimal 0/1 knapsack ():
- Item 1 alone: weight = 10, value = 60.
- Items 2 and 3: weight = , value = .
- Items 2 and 4: weight = , value = .
- Items 3 and 4: weight = , value = .
The maximum achievable value is .
Compute difference:
16
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2018 Computer Science and Information Technology (CS)
- Question
- 58 of 65, printed as CS Q.48
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.