0-1 Knapsack problem - Inside code

Sdílet
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

Komentáře • 15

  • @sproga_265
    @sproga_265 Před 2 lety +5

    It was interesting to see an actual mathematical solution to this. I've been solving stuff like this w/ Excel's Solver for years

  • @lordsixth5944
    @lordsixth5944 Před 2 lety +1

    Cant thank you more just wanted this problem to understand dp . Lot of love to you

  • @leenavig3441
    @leenavig3441 Před rokem

    very brilliantly explained. Lot of hard work to put this video together. Thank you for your effort!

  • @anishlushte4319
    @anishlushte4319 Před rokem +3

    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)

  • @abdulrehmanamer4252
    @abdulrehmanamer4252 Před rokem +2

    Bro you really made my day..
    I was stuck on it since the day 01.....
    Alhamdulillah!

  • @coding953
    @coding953 Před 4 měsíci

    There is a small mistake:
    `if(k

  • @subee128
    @subee128 Před 2 měsíci

    Thanks

  • @omerfeyyazselcuk7325
    @omerfeyyazselcuk7325 Před rokem

    thanks

  • @mytube5182
    @mytube5182 Před 2 lety +1

    doubt:
    how do i known which elements i have selected when i found max total value.

    • @Daniel_WR_Hart
      @Daniel_WR_Hart Před rokem +1

      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

  • @jimbobago
    @jimbobago Před 2 lety +1

    FYI: dollar signs are written *before* the number - $20, not 20$.