0-1 Knapsack problem - Inside code
Ғылым және технология
Source code: gist.github.com/syphh/955b71b...
Slides: 1drv.ms/p/s!AhunTZOxJvfsiiuV2...
🔴 Learn graph theory algorithms: inscod.com/graphalgo
⚙ Learn dynamic programming: inscod.com/dp_course
💡 Learn to solve popular coding interview problems: inscod.com/50problems_course
⌛ Learn time and space complexity analysis: inscod.com/complexity_course
🔁 Learn recursion: inscod.com/recursion_course
NB: This video is ad-free, you can choose to support Inside code by purchasing one of the courses above or dropping a super thanks!
NB2: Discounts of courses above are permanent
I also post content on LinkedIn (inscod.com/linkedin) and Instagram (inscod.com/instagram)
Пікірлер: 15
It was interesting to see an actual mathematical solution to this. I've been solving stuff like this w/ Excel's Solver for years
Need correction in code to check if weight is becoming negative before adding. let values= [ 60, 100, 120 ]; let weights = [ 10, 20, 30 ]; K = 50 code will return 280 instead of 220. Fix: if (weights[i] > k) return knapsack(values, weights, k, i+1)
@coding953
3 ай бұрын
Or Put `if(k
very brilliantly explained. Lot of hard work to put this video together. Thank you for your effort!
Cant thank you more just wanted this problem to understand dp . Lot of love to you
There is a small mistake: `if(k
Bro you really made my day.. I was stuck on it since the day 01..... Alhamdulillah!
@abdulrehmanamer4252
Жыл бұрын
And BTW nice animations!!
Thanks
thanks
doubt: how do i known which elements i have selected when i found max total value.
@Daniel_WR_Hart
Жыл бұрын
You can use a stack or a set to track the indices of the currently used elements, just make sure to remove the right indices from the collection when you backtrack
FYI: dollar signs are written *before* the number - $20, not 20$.
@koushikreddy6718
Жыл бұрын
so waht??