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 knapsack problem: you are given
items, where the th item has weight and value both nonnegative integers and a non
negative weight capacity of the knapsack. An optimal solution is a subset Ssubedots,
of the items having maximum total value
under the constraint that the total weight is at most the knapsack capacity, ie
In this problem, we introduce the fractional variant of the knapsack problem, where one may
take any fraction of any item Naturally, a fraction of item i weighs and
has value 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 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 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 from largest to smallest the
algorithm considers them in this order Let ALGdots, be the fractions of items
dots, chosen by the algorithm, respectively. So if the algorithm chooses all of
item and if it doesn't choose any of item
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 such that OPT
does not have exactly a fraction of item
You will construct another optimal solution whose fractions of the first items are
exactly dots, by modifying OPT, using an exchange argument.
Describe which fractions of items to exchange, and prove that meets the stated
requirements; this should include a proof that is a valid solution.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
