Skip to content
GATEiit

GATE CSE 2018 Q58: Optimal minus greedy value for 0/1 knapsack with capacity 11

Syllabus topic: Algorithm design techniques: greedy, dynamic programming and divide-and-conquer

Question

Consider the weights and values of items listed below. Note that there is only one unit of each item.

Item numberWeight (in Kgs)Value (in Rupees)
11060
2728
3420
4224

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 Vopt. 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 Vgreedy.

The value of Vopt−Vgreedy is ____________.

Try it: numerical answer: type the value

Numerical answer. No negative marking.
Show answer and explanation

Answer: 16 (official GATE 2018 final answer key)

Concept used: Greedy by value-to-weight ratio is optimal for fractional knapsack but can be suboptimal for 0/1 knapsack.

Concept notes

Loading notes…

First step: Compute each item's value/weight ratio, simulate the greedy packing with capacity 11, and separately check all feasible subsets for the optimum.

Full step-by-step solution

Loading…

Answer from the official final answer key. Found a mistake? Use Report issue and we will fix it.

More questions on Algorithm design techniques: greedy, dynamic programming and divide-and-conquer

Every PYQ on this topic →

Share this question

WhatsAppDownload image

Source: official GATE 2018 CS question paper and final answer key, organised by IIT Guwahati. Question paper · Answer key