0-1 Knapsack problem - Inside code
Vložit
- čas přidán 27. 02. 2022
- 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) - Věda a technologie
It was interesting to see an actual mathematical solution to this. I've been solving stuff like this w/ Excel's Solver for years
Cant thank you more just wanted this problem to understand dp . Lot of love to you
very brilliantly explained. Lot of hard work to put this video together. Thank you for your effort!
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)
Or Put `if(k
Bro you really made my day..
I was stuck on it since the day 01.....
Alhamdulillah!
And BTW nice animations!!
There is a small mistake:
`if(k
Thanks
thanks
doubt:
how do i known which elements i have selected when i found max total value.
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$.
so waht??