GATE CS 2018 · Asymptotic Analysis & Recurrences

NAT · 2 marks · Problem PROG-DIVC-0090

Consider the weights and values of items listed below. Note that there is only one unit of each item.\[\begin{array}{|c|c|c|}\hline \text{Item number} & \text{Weight (in Kgs)} & \text{Value (in Rupees)}\\ \hline 1 & 10 & 60\\ 2 & 7 & 28\\ 3 & 4 & 20\\ 4 & 2 & 24\\ \hline \end{array}\]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 \(V_{opt}\). 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 \(V_{greedy}\).The value of \(V_{opt}-V_{greedy}\) is

Numerical answer (NAT).

Solve it on GATE DA practice →More Searching & Sorting Algorithms problems

Show the worked solution\[\boxed{\text{greedy by } v/w \text{ is not optimal for 0/1 knapsack}}\]Ratios: item 1: \(6\), item 2: \(4\), item 3: \(5\), item 4: \(12\). Order: 4, 1, 3, 2.Greedy: take item 4 (2 kg, 24); item 1 does not fit (12 kg); take item 3 (6 kg, 44); item 2 does not fit (13 kg). \(V_{greedy}=44\).Optimal: item 1 alone gives 60 (10 kg); the best without item 1 is items 2 and 4 (9 kg, 52). \(V_{opt}=60\).\[V_{opt}-V_{greedy}=60-44=16.\]Answer: 16

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com