GATE / CS ARCHIVE

GATE CSE 2018 / QUESTION 48

Greedy versus optimal 0/1 knapsack

Algorithms · Greedy Algorithms · Full GATE CSE 2018 paper

GATE 2018, Q48 2 marks · NAT
Report issue

Greedy Algorithms

Question 48, GATE 2018: Capacity is 11 kg. Single available items (weight,value) are 1:(10,60),2:(7,28),3:(4,20),4:(2,24). Items cannot split. Greedy scans descending value/weight, taking items that fit. Find optimal value minus greedy value.
Tap to enlarge
Answer & solution

Official answer: 16

Step through it (2 tables)

Method

The ratio order is item 4 then 1 then 3 then 2. Taking item 4 leaves 9 kg, so item 1 no longer fits. Item 3 then fits and leaves 5 kg, too little for item 2. To verify optimality, item 1 alone gives 60 and cannot pair with even the smallest other item. Without item 1, feasible pairs (2,3),(2,4),(3,4) have values 48,52,44; all three weigh 13 and are infeasible. Thus exhaustive feasible alternatives confirm the optimum.

Solution

Value/weight ratios order the items as 4, 1, 3, 2, with ratios 12, 6, 5, 4. Greedy takes item4 (weight 2, value 24), skips item1 because it no longer fits, then takes item3 (weight 4, value 20), and skips item2. Its value is 44. The best feasible subset is item1 alone, value 60: pairs among 2, 3, 4 have maximum 52, all three weigh13, and item1 cannot accompany any other item under capacity 11. Hence60−44=16.

Original paper, page 20 · Answer key