How can i prove that Fractional Knapsack exhibits Greedy Strategy,
I can do it practically but i am not able to find a method to prove it theoretically.?
Please help Thanks in Advance
How can i prove that Fractional Knapsack exhibits Greedy Strategy,
I can do it practically but i am not able to find a method to prove it theoretically.?
Please help Thanks in Advance
We need to show that this problem has the greedy choice property. To do this, we need to show that any solution X
which does not include the greedy choice a
does not have get a worse solution after swapping some choice with a
.
For fractional knapsack, this is very easy to show: we take any element of X
, say b
. If wa >= w'b (where wa is the weight of a
, and w'b is the weight b
has in the solution X
), we can replace b
with as large a fraction of a
as possible. Because a
is the item with the largest value-density (this is our greedy choice), this will not make the solution worse. If wa < w'b we can take all of a
, and make w'b = w'b - wa. Again, because a
has the largest value-density, this does not make the solution worse.
That's it! We technically also need to show optimal substructure, but that should be fairly straightforward for this problem.
The (primal) fractional knapsack LP is
maximize sum_{i=1}^n v_i x_i
subject to
y: sum_{i=1}^n w_i x_i <= W
z_i: x_i <= 1 (for i=1 to n)
x_i >= 0 (for i=1 to n),
where v_i
is the value of item i
, and w_i
is the weight. The dual LP is
minimize W y + sum_{i=1}^n z_i
subject to
x_i: w_i y + z_i >= v_i
y >= 0
z_i >= 0 (for i=1 to n).
By (weak) LP duality, if the greedy solution to the primal has the same objective as a solution to the dual, then both are optimal. Assume that all weights are positive, that their sum is greater than W
, and that the item are ordered so that v_1/w_1 >= v_2/w_2 >= ... >= v_n/w_n
. Let j
be the pivot item, so that the greedy primal solution is
x_1, x_2, ..., x_{j-1} = 1
x_j = (W - sum_{i=1}^{j-1} w_i) / w_j
x_{j+1}, x_{j+2}, ..., x_n = 0.
By complementary slackness, we can guess that, in the dual, we should have
z_j, z_{j+1}, ..., z_n = 0.
The x_i
constraint in the dual is equivalent to
y + z_i/w_i >= v_i/w_i,
so we need to set
y >= v_j/w_j >= v_{j+1}/w_{j+1} >= ... >= v_n/w_n
in order to satisfy the constraints where we have zeroed z_i
. On a hunch, we set
y = v_j/w_j,
which intuitively forces the assignments
z_i = (v_i/w_i - v_j/w_j) w_i (for i=1 to j-1).
Now comes the only part of this argument that needs to be rigorous: verifying that this is a feasible solution to the dual (tedious and thus left as an exercise) and that the objective matches the greedy primal solution. The objective is
W y + sum_{i=1}^{j-1} z_i =
W (v_j/w_j) + sum_{i=1}^{j-1} (v_i/w_i - v_j/w_j) w_i =
sum_{i=1}^{j-1} (v_i/w_i) w_i + (v_j/w_j) (W - sum_{i=1}^{j-1} w_i) =
sum_{i=1}^{j-1} v_i + ((W - sum_{i=1}^{j-1} w_i) / w_j) v_j,
which is indeed the primal objective.