Hey Every one, If you find this tutorial helpful, please do not forget to like, comment, share and It would be great if you can leave your feedback about the tutorial, as I have put a lot of hard work to make things easy for you. Thanks ..!!
Hello Sir, I was thinking of this method, please tell me whether this method will work or not. 1. Take all 'n' inputs and calculate value per unit weight (unitvalue = value/weight) for every item 2. Store unitvalue of every item in an array. 3. Now arrange the unitvalue array in descending order, and simultaneously arrange value and weight array according to unit value such that the item's value, weight and unitvalue remains in the same column (3*n array). 4. Now using FOR LOOP and IF condition collect maximum value items in the bag. SAMPLE CODE- for(i=1;i
knapsack problem has two variants- 1) 0/1 knapsack 2) fractional knapsack This tutorial cover 0/1 knapsack problem but your query is regarding fractional knapsack which requires greedy approach to solve.
In this whole vedio I have one doubt if the input array is starting from zero then we should take v[i + 1] right .but sir u are saying v[i - 1] there I got confused. Can u explain my doubt.
If you use 1D araay for storing only value then how will you fetch the exact capacity, against a particular weight.you need to store the weight -capacity mapping somewhere.
Because knapsack has rule : In the classical 0/1 Knapsack problem, you are not allowed to take multiple units of the same item. Each item can be included in the knapsack at most once (0 or 1 times). Therefore, you cannot take 3 units of an item with weight 3 and value 50.
Guys, just one tip- Don't close this video just because it's too long. *Go through the complete video to understand the concept and learn multiple ways to solve knapsack problem.* You will really love it. 👌😍 Now i will never forget knapsack problem.
As we have capacity C=4 lb. if we choose laptop of worth Rs. 300$ having weight 3lbs, then still knapsack bag has 1lbs capacity which we are not utilising. so to get maximum profit will choose phone(150$ with 1lb)+ tablet(200$ with 3lb) = 350$ with 4lb