KNAPSACK Optimization Problem using Greedy
Method
Problem 1:
Item Weight Value
1 14 20
2 6 16
3 10 8
4 5 10
5 4 12
Allowed weight = 24 Kg
Problem 2:
Item Weight Value
1 6 30
2 8 40
3 15 45
4 22 88
5 25 80
Allowed weight = 60 Kg
Problem 3:
Item Weight Value
1 6 30
2 8 40
3 15 45
4 22 88
5 25 80
Allowed weight = 60 Kg
Solution 1:-
Item | Value | Weight | Value/Weight |
1 | 20 | 14 | 1.42 |
2 | 16 | 6 | 2.66 |
3 | 8 | 10 | 0.8 |
4 | 10 | 5 | 2 |
5 | 12 | 4 | 3 |
Arranging items in decreasing order of Value/Weight: 5 , 2 , 4 , 1 , 3. Now the items will be put in the bag in this order.
Allowed weight = 24 kg
Items put in the bag | Value | Weight in the bag |
5 | 12 | 4 |
2 | 16 | 6 |
4 | 10 | 5 |
1 | 9 * 20/14 | 9 |
Total value = 50.85
Solution 2:-
Items | Value | Weight | Value/Weight |
1 | 30 | 6 | 5 |
2 | 40 | 8 | 5 |
3 | 45 | 15 | 3 |
4 | 88 | 22 | 4 |
5 | 80 | 25 | 3.2 |
Decreasing order of Value/Weight : 1,2,4,5,3
Allowed weight = 60 kg
Items put in the bag | Value | Weight in the bag |
1 | 30 | 6 |
2 | 40 | 8 |
4 | 88 | 22 |
5 | 24*3.2 | 24 |
Total value= 234.8
Solution 3:-
It has same values as that of Problem 2 so the solution is also same.
Get Answers For Free
Most questions answered within 1 hours.