Knapsack Problem with example
Knapsack Problem
Objects | Obj1 | Obj2 | Obj3 |
---|---|---|---|
Profit | 25 | 24 | 15 |
Weight | 18 | 15 | 10 |
Proportion | 1:3 | 1:6 | 1:5 |
We have, Capacity of Knapsack (M) = 20
Let’s see two approach
→ I am Greedy about Profit
Profit | obj1 25 | 2/15 * 24 | =28.2 |
---|---|---|---|
Weight | 18 | 2 | =20 |
→ Greedy about Weight
Weight | obj3 10 | obj2 10 of 15 | =20 |
---|---|---|---|
Profit | 15 | 10/15 *24 | =31 |
→ Greedy about Both by Profit/Weight Proportion that will be 1:3 1:6 1:5
Weight | obj2 15 | obj3 5 of 10 | =20 |
---|---|---|---|
Profit | 24 | 5/10 *15 | =31.5 |
So, when we took the proportion we got maximum approach. Thus, this approach was suitable.
The , pseudocode for the problem looks like:
Post a Comment