## 0/1-Knapsack-and-fractional-knapsack

Question 1 |

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

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 ______ .

16 | |

17 | |

18 | |

19 |

Question 1 Explanation:

First sort value/weight in descending order as per the question:

V

For V

Item 4 picked,

Profit = 24

Remaining weight = 11 – 2 = 9

Next item 3 picked (item 1 cannot be picked since its capacity is greater than available capacity),

Profit = 24 + 20 = 44

Remaining capacity = 9 – 4 = 5

Now no item can be picked with available capacity.

So V

∴ V

V

_{opt}is clearly = 60For V

_{greedy}use the table (Do not take the fraction as per the question),Item 4 picked,

Profit = 24

Remaining weight = 11 – 2 = 9

Next item 3 picked (item 1 cannot be picked since its capacity is greater than available capacity),

Profit = 24 + 20 = 44

Remaining capacity = 9 – 4 = 5

Now no item can be picked with available capacity.

So V

_{greedy}= 44∴ V

_{opt}– V_{greedy}= 60 – 44 = 16
There is 1 question to complete.