KNAPSACK PROBLEM
JUNE 2014 - PAPER III Q.No 62
62. Consider the fractional knapsack instance n=4, (p1,p2,p3,p4) = (10,10,12,18)(w1,w2,w3,w4)=(2,4,6,9) and M=15. The maximum profit is given by,
(Assume p and w denotes profit and weights of objects respectively).
(A)40
(B)38
(C)32
(D)30
Ans:-B
Explanation:-
Knapsack problem can be solved either using Greedy approach or through Dynamic programming. I am going to be explaining using the former. It has been proved that for the knapsack problem using greedy method we always get the optimal solution provided the objects are arranged in decreasing order of pi/wi. So, before solving the problem, let us arrange all the objects in decreasing order of pi/wi.
Capacity of the knapsack M = 15
Number of objects = 4
Profits(p1,p2,p3,p4)=(10,10,12,18)
Weights(w1,w2,w3,w4)=(2,4,6,9)
To get the solution arrange objects in decreasing order of profit/weights as shown below.
p1/w1=10/2 =5
p2/w2=10/4=2.5
p3/w3=12/6=2
p4/w4=18/9=2
Arrange in decreasing order of pi/wi, we get
Object | Weight | Profit | Pi/wi |
---|---|---|---|
1 | 2 | 10 | 5 |
2 | 4 | 10 | 2.5 |
3 | 6 | 12 | 2 |
4 | 9 | 18 | 2 |
The fractions of the objects selected and the profit we get can be computed as shown below:
Remaining Capacity | Object selected | Weight of the object | Fraction of the object selected |
---|---|---|---|
15 | 1 | 2 | 1 full unit |
15-2=13 | 2 | 4 | 1 full unit |
13-4=9 | 3 | 6 | 1 full unit |
9-6=3 | 4 | 9 | 3/9 or 1/3 fraction of unit |
So, the solution vector will be=(1,1,1,1/3)
Profits=1 X 10 + 1 X 10 + 1 X 12 + 1/3 X 18
Profits=10+10+12+6
Profits=20+18
=38
So the correct answer will be 38. The maximum profit is given by option (B) which is 38.
Solve the following problem and see.
I. Obtain the optimal solution for the knapsack problem given the following: M=40,n=3, (p1,p2,p3)=(30,40,35) and (w1,w2,w3)=(20,25,10).
.
The answer for the above problem is 82.5
Check it by working out.
Thanks ur blog is very helpful for ugc net aspirants
ReplyDeleteThanks ur blog is very helpful for ugc net aspirants
ReplyDeleteI am nt understanding plz can u explain me
ReplyDeletePls explain how we get remaining capacity value
ReplyDeletewhat is the difference between optimal solution and maximum profit
ReplyDeletecan anyone tell me how do we get the fraction of the object
ReplyDeleteThanks your blog is extremely helpful for net aspirants.
ReplyDeleteAnybody can solve this question?
ReplyDeleteConsider the 0/1 Knapsack instance, n=4 , (p1,p2,p3,p4) = (11,21,31,33) (w1,w2,w3,w4) =(2,11,22,15) M =40.. assume P and W denotes profit and weight of the object respectively.. the maximum profit is given by ..
Use backtracking algorithm to maximize the profit of 0/ 1 knapsack problem instance
ReplyDeletewhere n = 4, (p1, p2, p3, p4) = (10, 30, 40, 50), (w1, w2, w3, w4) = (5, 5, 2, 10) and
m = 16. Draw the corresponding state space tree.
11+33+21= 65answer
ReplyDeleteas we calculate Pi/Wi
so as we take complete item so we can only pick the top items with full weight
find an optimal solution to the knapsack instance n=9,w=12,(v1,v2,v3,v4,v5,v6,v7)=(16,5,15,7,16,18,3) and(w1,w2,w3,w4,w5,w6,w7)=(3,3,4,7,1,4,1).
ReplyDeletePlease answer me for this question
DeleteConsider the knapsack instance with 5 object and a capacity M=11, Profits P=(5,4,7,2,3) anf weight W= (4,3,6,2,2).
ReplyDeleteSolve it using dynamic programming approach.