0/1 knapsack problem
In 0/1 Knapsack Problem,
Amity School of Engineering & Technology
Find the optimal solution for the 0/1 knapsack problem making use of dynamic programming approach. Consider-
n = 4
C= 8kg
P= (1,2,5,6)
W= (2,3, 4, 5)
Amity School of Engineering & Technology
0/1 Knapsack Problem Using Dynamic Programming-�
Step-01:
Amity School of Engineering & Technology
Amity School of Engineering & Technology
Step-02:
T (i , j) = max { T ( i-1 , j ) , valuei + T( i-1 , j – weighti ) }
Here, T(i , j) = maximum value of the selected items if we can take items 1 to i and have weight restrictions of j.
Amity School of Engineering & Technology
Step-03:
To identify the items that must be put into the knapsack to obtain that maximum profit,
Amity School of Engineering & Technology
Problem-2
Find the optimal solution for the 0/1 knapsack problem making use of dynamic programming approach. Consider-
n = 4
C= 5 kg
(w1, w2, w3, w4) = (2, 3, 4, 5)
(b1, b2, b3, b4) = (3, 4, 5, 6)
Amity School of Engineering & Technology
Amity School of Engineering & Technology
Amity School of Engineering & Technology
Problem-3
Find the optimal solution for the 0/1 knapsack problem making use of dynamic programming approach. Consider-
n = 5
C= 11 kg
(w1, w2, w3, w4,w5) = (1,2,5,6,7)
(p1,p2,p3,p4,p5) = (1,6,18,22,28)
Amity School of Engineering & Technology
Answer
Amity School of Engineering & Technology