Fractional Knapsack Problem
Fractional Knapsack Problem
?
Knapsack Problem – in Short
• A thief considers taking W pounds of loot. The
loot is in the form of n items, each with weight
wi and value vi. Any amount of an item can be
put in the knapsack as long as the weight limit
W is not exceeding.
Knapsack Problem – 2 types
max imize px
1i n
i i
subject to w x m and 0 x 1, 1 i n
1i n
i i i
10 lb
W=
25lb
$90 $140 $70
5 lb
25 lb
$70 25 lb
10 lb $90
5 lb 10 lb
Greedy vs Dynamic 9
Greedy 2: Selection criteria: Minimum
weight item
Counter Example:
S = { ( item , 5, $150 ), (item ,10, $60 ), ( item , 20, $140 ) }
1 2 3
5 lb
$140
W=
30lb $140
20 lb
$60 $60
20 lb 10 lb
$150 10 lb
$150
5 lb $150 5 lb
5 lb
item1 item2 item3 Knapsack Greedy Optimal =$290
Solution
=$210 Solution
Greedy vs Dynamic 10
Greedy 3: Selection criteria: Maximum
weight item
Counter Example:
S = { ( item , 5, $150 ), (item ,10, $60 ), ( item , 20, $140 ) }
1 2 3
5 lb
10 lb
$60
$140
W=
30lb $140
20 lb
$60
20 lb
$150 10 lb 20 lb
$140 $150
5 lb 5 lb
Greedy vs Dynamic 11
Greedy 4: Selection criteria: Maximum
benefit per unit item Counter
Example
S = { ( item1 , 5, $50 ), ( item2, 20, $140 ) (item3 ,10, $60 ), }
5 lb
B/W: $7
$140
W=
30lb 20 lb $140
$140
B/W 2: $6
20 lb
B/W 1: $10 $60
20 lb
$50 10 lb $60
10 lb $50
5 lb 5 lb