Question: Recall the knapsack problem ( sometimes called the 0 - 1 knapsack problem ) : you are given n items, where the i

Recall the knapsack problem (sometimes called the "0-1" knapsack problem): you are given n
items, where the i th item has weight wi and value vi(both non-negative integers), and a non-
negative weight capacity W of the knapsack. An optimal solution is a subset Ssube{1,2,dots,n}
of the items having maximum total value
iinS?vi
under the constraint that the total weight is at most the knapsack capacity, i.e.,
iinS?wiW In this problem, we introduce the fractional variant of the knapsack problem, where one may
take any fraction piin[0,1] of any item i. Naturally, a pi-fraction of item i weighs pi*wi, and
has value pi*vi. The goal is to maximize the total value of the selected fractional items. (c) Consider the following greedy algorithm for the fractional knapsack problem:
RelativelyGreedy: While there is still some unused knapsack capacity, choose an
item having the largest relative value viwi(among those not considered yet), and add
the largest possible fraction of that item (up to the full item) that will fit within the
remaining knapsack capacity.
In this part, you will prove that the RelativelyGREEDY algorithm is a correct algorithm
for the fractional knapsack problem. This is notable because we used a more complicated
dynamic programming algorithm to solve 0-1 Knapsack, but the fractional variant admits
a much simpler greedy algorithm!
The setup for your correctness proof is as follows. Without loss of generality, suppose that
the items are in sorted order by relative value ri=viwi, from largest to smallest (the
algorithm considers them in this order). Let ALG=p1,p2,dots,pn be the fractions of items
1,2,dots,n chosen by the algorithm, respectively. (So,pi=1 if the algorithm chooses all of
item i, and pi=0 if it doesn't choose any of item i.)
Let OPT be an arbitrary optimal solution. If ALG= OPT, then ALG is optimal, as
needed. So suppose that ALG OPT, and consider the smallest index j such that OPT
does not have exactly a pj-fraction of item j.
You will construct another optimal solution OPT' whose fractions of the first j items are
exactly p1,p2,dots,pj by modifying OPT, using an exchange argument.
Describe which fraction(s) of item(s) to exchange, and prove that OPT' meets the stated
requirements; this should include a proof that OPT' is a valid solution.
Recall the knapsack problem ( sometimes called

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!