Fractional KnapsackFractions of items can be taken rather than having to make binary (01) choices for each item. Fractional Knapsack Problem can be solvable by greedy strategy whereas 0  1 problem is not. Steps to solve the Fractional Problem:
Fractional Knapsack (Array v, Array w, int W) 1. for i= 1 to size (v) 2. do p [i] = v [i] / w [i] 3. SortDescending (p) 4. i ← 1 5. while (W>0) 6. do amount = min (W, w [i]) 7. solution [i] = amount 8. W= Wamount 9. i ← i+1 10. return solution Example: Consider 5 items along their respective weights and values:  I = (I_{1},I_{2},I_{3},I_{4},I_{5}) w = (5, 10, 20, 30, 40) v = (30, 20, 100, 90,160) The capacity of knapsack W = 60 Now fill the knapsack according to the decreasing value of p_{i}. First, we choose the item I_{i} whose weight is 5. Then choose item I_{3} whose weight is 20. Now,the total weight of knapsack is 20 + 5 = 25 Now the next item is I_{5}, and its weight is 40, but we want only 35, so we chose the fractional part of it, Solution:
Taking value per weight ratio i.e. p_{i}=
Now, arrange the value of p_{i} in decreasing order.
Next TopicHuffman Codes
