DP 19. 0/1 Knapsack | Recursion to Single Array Space Optimised Approach | DP on Subsequences

แชร์
ฝัง
  • เผยแพร่เมื่อ 20 ก.ค. 2024
  • Lecture Notes/C++/Java Codes: takeuforward.org/dynamic-prog...
    Problem Link: bit.ly/3KHpP3v
    Pre-req for this Series: • Re 1. Introduction to ...
    a
    Make sure to join our telegram group for discussions: linktr.ee/takeUforward
    Full Playlist: • Striver's Dynamic Prog...
    In this video, we solve the problem of 0/1 Knapsack. We start with memoization, then tabulation, then two-row space optimization, then single row optimisation. This problem is the fifth problem on DP on Subsequences Pattern. Please watch DP 17 before watching this.
    If you have not yet checked our SDE sheet, you should definitely do it: takeuforward.org/interviews/s...
    You can also get in touch with me at my social handles: linktr.ee/takeUforward

ความคิดเห็น • 1.1K

  • @takeUforward
    @takeUforward  2 ปีที่แล้ว +233

    I need your support, and you can do that by giving me alike, and commenting "understood" if I was able to explain you. The single space thing can be applied to all the subset-sum problems as well.
    Keeping a like target of 500 ❤✌🏼

    • @mdmurtaza8321
      @mdmurtaza8321 2 ปีที่แล้ว +2

      one of the doubt i am getting how are u converting the base case of memorized code to tablar dp
      like in this case
      if(indx==0)
      {
      if(wt[0]

    • @sairishik229
      @sairishik229 ปีที่แล้ว

      can we take the starting value of take as -1 ??

    • @sayansadhukhan9692
      @sayansadhukhan9692 ปีที่แล้ว +4

      @@mdmurtaza8321 The dp is declared as dp[n][W+1]. In this base case we are trying(to handle index = 0 condition, i.e. 0th row on dp matrix) to fill dp[0][0 to maxWeight] so that filling dp for every weight till maxWeight. The for loop is starting with wt[0] because, the base condition is for 0th index i.e. 0th index wt[0] and we have minimum weight at 0th index, the thief can steal whatever element is there on index = 0 until weight of the element is less or equal to maxWeight (wt[0] to maxWeight) .

    • @stith_pragya
      @stith_pragya 6 หลายเดือนก่อน +2

      I checked the like count has crossed ever 7000😎

    • @iamnoob7593
      @iamnoob7593 6 หลายเดือนก่อน

      understood

  • @pranjalthapliyal2278
    @pranjalthapliyal2278 ปีที่แล้ว +164

    Understood :)
    Can't believe that I was able to solve one of the most famous problems out there on my first atttempt, completely on my own. You may never see this comment Striver, but this playlist is genuinely incredible, so thank you *sooooo* much for putting this incredible content out there, all for free.

  • @pragyajha5609
    @pragyajha5609 2 ปีที่แล้ว +162

    You are one of the most intelligent people I have ever seen. Not finished watching till end, just wanted to tell you. You make me feel I am intelligent too. Thanks @striver.

    • @udaypratapsingh8923
      @udaypratapsingh8923 ปีที่แล้ว

      u r right btw : )

    • @prajjwalgurjar3887
      @prajjwalgurjar3887 ปีที่แล้ว +1

      @@udaypratapsingh8923 ok bhay

    • @abhimanyuambastha2595
      @abhimanyuambastha2595 หลายเดือนก่อน +1

      Haven see a lot of DP videos, and mostly all of them write the space optimized code including the 1-D array, but not teaches exactly why they wrote it that way. Striver bro great teaching and energy, loved it

  • @kiransequeira6152
    @kiransequeira6152 ปีที่แล้ว +91

    space optimization to just 1D array was insane 🤯

    • @MadhavGupta-fi2tu
      @MadhavGupta-fi2tu ปีที่แล้ว

      why in tabulation base condition is from i=w[0] ?

    • @KinjalDas-ok9hu
      @KinjalDas-ok9hu ปีที่แล้ว +1

      @@MadhavGupta-fi2tu Compare it to the base condition in the recursive solution. We can add wt[0] our knapsack only if its value is less than the target w, so for the index i = 0, we simply looped over all values from wt[0] to the target value w.

    • @ankurgoswami4441
      @ankurgoswami4441 ปีที่แล้ว +1

      @@MadhavGupta-fi2tu because for i < w[0], dp[0][i] is 0, which is already pre filled at time of vector declaration

    • @KandulaAsrith
      @KandulaAsrith 6 หลายเดือนก่อน +1

      because, suppose that we landed at index=0, with the bag capacity still having >= weight[0], then we can definitely place the item which is at index 0 into the bag. So, for all the values of bag capacity>=weight[0], the value that we can return is value[0].

    • @aeshwer
      @aeshwer 2 หลายเดือนก่อน

      @@MadhavGupta-fi2tu //Base case - for all wieghts more than maxWeight at zero index will return value else return 0

  • @eshandhok2591
    @eshandhok2591 ปีที่แล้ว +36

    Mind Blowing Observation for that space optimization, things like these define the difference between a googler and any other person, lot's to learn from you, Striver, in terms of education as well as life lessons. As always, Understood!

    • @saketaryan2227
      @saketaryan2227 ปีที่แล้ว +3

      bruh u just made google sound like iit

  • @paridhijain7062
    @paridhijain7062 2 ปีที่แล้ว +56

    Understood, I am following this series. I have gone through a few of other playlists but this one is my constant now. Learning each day. You literally mad DP very easy to grasp now. Thank you sir.

    • @MadhavGupta-fi2tu
      @MadhavGupta-fi2tu ปีที่แล้ว

      why in tabulation base condition is from i=w[0] ?

    • @tanmaybro3812
      @tanmaybro3812 ปีที่แล้ว +1

      @@MadhavGupta-fi2tu The for loop is starting with wt[0] because, the base condition is for 0th index i.e. 0th index wt[0] and we have minimum weight at 0th index, the thief can steal whatever element is there on index = 0 until weight of the element is less or equal to maxWeight (wt[0] to maxWeight) .

    • @user-hq6vy2dj7d
      @user-hq6vy2dj7d 15 วันที่ผ่านมา

      Hey i am learning dev from harkirat wanna ask how to start dsa journey will you please guide me

  • @ayushsharma7946
    @ayushsharma7946 2 ปีที่แล้ว +9

    The way striver say "WHAT ARE YOU WAITING FOR?" always motivates me more and fills more energy into me..!! Thanks a lot striver.

  • @yamanaggarwal6391
    @yamanaggarwal6391 2 ปีที่แล้ว +17

    I saw so many articles which used just a single array for space optimization and was never able to understand it. Everybody had given vague answers about this and I had literally scouted the entire internet for this explanation. And today I am finally able to understand it. Thank you so much Striver bhaiya. There is no match of you 🙏🙏🙏

  • @anmolmajhi225
    @anmolmajhi225 2 ปีที่แล้ว +14

    Thanks, sir, without seeing this video I can do recursive, recursive with memoization, tabulation and space optimization with two arrays by learning last 18 lectures, and now I can do the one array optimization. This DP series has helped me solve questions easily that I can't previously. Once again Thank you for bringing this amazing DP series. LOVE your work. And Lastly UNDERSTOOD!!❤❤

    • @MadhavGupta-fi2tu
      @MadhavGupta-fi2tu ปีที่แล้ว

      why in tabulation base condition is from i=w[0] ?

    • @kushalcg3175
      @kushalcg3175 10 หลายเดือนก่อน

      @@MadhavGupta-fi2tu Because it is from that index that the item at index 0 can be picked up, before that the maximum weight that we can hold will be lesser than the weight of item 0

  • @nishitar3915
    @nishitar3915 6 วันที่ผ่านมา +1

    Every single time you amaze me Raj!!! Hats off to your hardwork man!! Big Salute. And most importantly very grateful to be having taught by you!!!!!!

  • @sharan7504
    @sharan7504 2 ปีที่แล้ว +1

    UNDERSTOOD!! that single array space optimization is mind blowing!!...really loved it! THANK YOU SOOO MUCH

  • @jaiminsolanki5478
    @jaiminsolanki5478 2 ปีที่แล้ว +13

    Even in the most common problem, Striver teaches something new, thankyou so much Raj Bhaiya!

  • @alokkumar-ki7wp
    @alokkumar-ki7wp ปีที่แล้ว +6

    I never thought I could be able to solve DP problems all by myself, but just a moment ago I did!!!! Thank you striver, You're amazing.

    • @MadhavGupta-fi2tu
      @MadhavGupta-fi2tu ปีที่แล้ว

      why in tabulation base condition is from i=w[0] ?

    • @brokegod5871
      @brokegod5871 10 วันที่ผ่านมา

      @@MadhavGupta-fi2tu because you are going from n-1 to 0, so in the last case you have one item left to steal which is basically the 0th item

  • @KalingaAbhisek
    @KalingaAbhisek ปีที่แล้ว +2

    At the end of the video space optimisation you told me i was doing the same way in previous questions when i figured it out myself that if we are using previous element of previous array then why dont we traverse backward and compute and store there in that previous array. Now you did it and now i am sure about the optimisation i was thinking.
    I bet that I Understood............🙂🙏

  • @vibhavsharma2724
    @vibhavsharma2724 2 หลายเดือนก่อน +1

    Unbelievable that you optimize the code this much. Really you are an extraordinary person. I understood it very clearly. Thank you striver.

  • @shubhankarsharma154
    @shubhankarsharma154 ปีที่แล้ว +6

    Single row optimization was really a god tier stuff... ⚡
    Thank you and UNDERSTOOD

  • @parthsalat
    @parthsalat 2 ปีที่แล้ว +9

    Understood kaka
    The optimisation into a single vector was mind blowing!
    You clearly deserve Google Warsaw!

    • @karthikeyan1996_
      @karthikeyan1996_ ปีที่แล้ว +2

      it is already in geeks for geeks if you havent seen this before dude nothing out of the moon

    • @MadhavGupta-fi2tu
      @MadhavGupta-fi2tu ปีที่แล้ว

      why in tabulation base condition is from i=w[0] ?

    • @rahulmandal4007
      @rahulmandal4007 หลายเดือนก่อน

      @@karthikeyan1996_ zyada mat bol Adress bata apna pilna h to

  • @harshitgupta7496
    @harshitgupta7496 3 หลายเดือนก่อน +1

    Thanks striver! Watched the dp lecture in series. Was able to come up with recursion , tabulation and space optimization into 1D all by myself!

  • @zen-g-host
    @zen-g-host ปีที่แล้ว +2

    Hi striver! You are really an amazing person and best mentor we could have asked for, i can't tell you how much gratitude I have for you.
    Once again Understood!!!

  • @meetsoni1938
    @meetsoni1938 2 ปีที่แล้ว +25

    You are travelling a whole journey from recursion-> memorization -> Space Optimisation that is amazing. No one else explain like that 🦾💪💪

    • @jiteshkhatri2896
      @jiteshkhatri2896 ปีที่แล้ว

      Aditya Verma also explained in same way and in depth also

    • @ch0c0_1
      @ch0c0_1 ปีที่แล้ว +3

      Tabulation also 🔥

    • @jeevaalok1467
      @jeevaalok1467 ปีที่แล้ว

      @@jiteshkhatri2896 who's is best at teaching everything briefly in your pov ?

    • @jiteshkhatri2896
      @jiteshkhatri2896 ปีที่แล้ว

      @@jeevaalok1467 if u want can share any social media handle where we can discuss.

    • @naveenramadheni2482
      @naveenramadheni2482 ปีที่แล้ว

      ​@@jeevaalok1467Both are of the same standards, but I chose a striver from Aditya verma becoz I can't understand Hindi.

  • @itsaryanb9316
    @itsaryanb9316 ปีที่แล้ว +3

    Loved the Single Array space optimised approach !!

  • @shineinusa
    @shineinusa 2 ปีที่แล้ว +6

    First of all thank you for the series. I believe the base cases from the previous and this video are un necessarily complicated. You can just check if(idx < 0 || w == 0) { return 0;}, we don't have to make 0 as a special case and write confusing base cases (if else's). once the index 0 is processed like rest of the others indexes, it should stop. I hope you take it as a constructive criticism!☮

    • @SJ_46
      @SJ_46 2 ปีที่แล้ว +2

      That's right if we only had to do rec and memoization, but in tabulation how will u initialize negastive index?? Ik it can be done, but then memo to tabu step will involve some extra work which is avoided if we do this way, also why will the fn have to handle a negative index in the first place?? it will never occur, idx is always >=0, in yr case it is becoming

    • @cse048harshkumawat6
      @cse048harshkumawat6 ปีที่แล้ว +1

      @@SJ_46 why we didn't write when
      if(W==0)
      return 0;

    • @amansaxena5620
      @amansaxena5620 ปีที่แล้ว

      @@cse048harshkumawat6 did u find the answer because I am thinking the same?

    • @vinitkumawat2335
      @vinitkumawat2335 ปีที่แล้ว +2

      @@amansaxena5620​ @CSE048 Harsh Kumawat we are only taking particular element if it is less than or equal to W, So even if it becomes 0 in between, then we will keep moving towards base case, i.e. F(idx-1, W) => Eventually it will go in Base condition, and it will be handled there.

  • @Happy-tf7se
    @Happy-tf7se หลายเดือนก่อน

    DP used to be a nightmare, I sort of ran away from it but after following your playlist it seems something approachable. I am soo happy I am able to solve these on my own.

  • @vibhanshugarg3603
    @vibhanshugarg3603 2 ปีที่แล้ว

    this is the easiest ever explanation of 0/1 knapsack. Godly insane man!!!

  • @himanshuagrawal8012
    @himanshuagrawal8012 2 ปีที่แล้ว +3

    Great Series BHAIYA. You are doing a great job. Gradually now I am able to build logic and write the code on my own. #UNDERSTOOD

  • @balwantyadav724
    @balwantyadav724 2 ปีที่แล้ว +11

    US sir .. Love the single array optimization....keep going sir.

    • @MadhavGupta-fi2tu
      @MadhavGupta-fi2tu ปีที่แล้ว

      why in tabulation base condition is from i=w[0] ?

  • @Abcd-jt1qs
    @Abcd-jt1qs 19 วันที่ผ่านมา

    I could solve the recursive, memoisation, tabulation and space optimisation approach with 2 vectors on my own.. So thankful to you striver. The last space optimised method was very nice. Understood and a big big thank you :)

  • @yashkhatwani3198
    @yashkhatwani3198 ปีที่แล้ว +1

    Understood , solved all recursive , memoization , tabulation and space optimization by myself .

  • @Ani_86_
    @Ani_86_ 2 ปีที่แล้ว +6

    The single vector optimization was wonderful 🔥😅

  • @RupamSasmalYt
    @RupamSasmalYt ปีที่แล้ว +4

    From fearing from "DP" to solve question by my own without watching your solution, it's a great journey! BTW damn good observation to optimize it into single array! grateful ♥

    • @MadhavGupta-fi2tu
      @MadhavGupta-fi2tu ปีที่แล้ว

      why in tabulation base condition is from i=w[0] ?

  • @sonukumarram1880
    @sonukumarram1880 5 หลายเดือนก่อน +2

    single array technique was mind blowing concept ... thank u striver

  • @omeshdeoli9475
    @omeshdeoli9475 3 หลายเดือนก่อน

    was never able to understand how single array space optimisation works excellent explanation striver. Really helpful!!

  • @souravkumar-eb1wz
    @souravkumar-eb1wz 2 ปีที่แล้ว +4

    Understood Bro. The single array optimization was awesome . It showed the power keen observation 💥💥. Hope one day , I achieve such an observation skill. Thanks for the video bro. Keep the DP series going 💪💪.
    This is like my personal wish , i would like to see some DP problems based on subarrays in this series , because i find it hard differentiating it from subsequence problems. I believe only you can make me understand. Pls consider this bro.

    • @MadhavGupta-fi2tu
      @MadhavGupta-fi2tu ปีที่แล้ว +1

      why in tabulation base condition is from i=w[0] ?

  • @priyankasati8308
    @priyankasati8308 2 ปีที่แล้ว +4

    Awesome, seriously love the last 1d optimization.

    • @MadhavGupta-fi2tu
      @MadhavGupta-fi2tu ปีที่แล้ว

      why in tabulation base condition is from i=w[0] ?

  • @jidgesanathkumar8038
    @jidgesanathkumar8038 21 วันที่ผ่านมา

    All are born to go forward
    And then there is you, who was born to take us forward
    Living legend
    Striver sir...🙇🙇

  • @sangeethagopalan301
    @sangeethagopalan301 หลายเดือนก่อน +1

    Loved the single array optimisation. U r doing a brilliant job. Thanks a ton!!!

  • @jitendrasinghsola
    @jitendrasinghsola 2 ปีที่แล้ว +3

    What a amazing series i am able to do question on my own

    • @MadhavGupta-fi2tu
      @MadhavGupta-fi2tu ปีที่แล้ว

      why in tabulation base condition is from i=w[0] ?

  • @Saurav_Kumar514
    @Saurav_Kumar514 ปีที่แล้ว +3

    1D Array optimisation is really Awesome 🔥❤

    • @MadhavGupta-fi2tu
      @MadhavGupta-fi2tu ปีที่แล้ว

      why in tabulation base condition is from i=w[0] ?

  • @user-sw3oo9fr5l
    @user-sw3oo9fr5l 28 วันที่ผ่านมา

    Hello Sir this question seems to be a very simple and direct one when read for the first time if you have basic idea about DP on subsequences. But when you code it and visualise using the 2D DP array / matrix and check the test cases, only then one is blown away by the beauty of it. Also the manner how the previous Row is enough to evaluate maximum value adds to the class and excellence of the question !

  • @gauranggupta6422
    @gauranggupta6422 2 ปีที่แล้ว

    This is one of the best explanations of this question and the space optimization is just amazing. Thanks striver

  • @codermal
    @codermal 2 ปีที่แล้ว +6

    Those who thought of using greedy by sorting according to (val/wt),
    Test Case: wt-> 3 2 4
    bag=5 val->57 36 80
    greedy gives=) 80 , while ans=93

    • @avirupmazumder4840
      @avirupmazumder4840 ปีที่แล้ว +2

      That was fractional knapsack

    • @codermal
      @codermal ปีที่แล้ว

      @@avirupmazumder4840 In fractional knapsack we break items, but as you can see here we didn't break the item if we had broken items then greedy would have give (80 + 19) => 99

    • @atharvameher5880
      @atharvameher5880 7 หลายเดือนก่อน

      thanks...was confused@@codermal

  • @Raghav1205
    @Raghav1205 2 ปีที่แล้ว +3

    Bhaiya one suggestion can you please consider making a video on coin change type problems because it gets confusing when all the permutations are counted and in some only unique ones are counted.

    • @MadhavGupta-fi2tu
      @MadhavGupta-fi2tu ปีที่แล้ว

      why in tabulation base condition is from i=w[0] ?

  • @rameshsharma3639
    @rameshsharma3639 4 หลายเดือนก่อน

    No doubt why you are most loved teacher !! HATS OFF. ---> one array space optimization was something out of the box

  • @nagasrikuncharapu3736
    @nagasrikuncharapu3736 5 หลายเดือนก่อน +1

    I was able to write top down approach on my own. It's all because of the previous lectures. Thanks to you brother.

  • @polycarpvegas9446
    @polycarpvegas9446 2 ปีที่แล้ว +5

    POV : Educated guys do not steal 💀💀

  • @abdallaalhag4425
    @abdallaalhag4425 7 หลายเดือนก่อน

    understood, had to write it out to understand the tabulation logic but that made both space optimization a lot easier to understand.

  • @ranasauravsingh
    @ranasauravsingh 2 ปีที่แล้ว +1

    UNDERSTOOD.. !
    wooooooahhh that last space optimization climax gonna enlighten your brain nerves...
    Thanks striver for the video... :)

  • @ravikjha07
    @ravikjha07 2 ปีที่แล้ว

    It was amazing !!! I was trying it by myself but couldn't do the optimization in one Single Array, but now Understood !!!

  • @AMANKUMAR-eq6sq
    @AMANKUMAR-eq6sq 2 ปีที่แล้ว +2

    I bet no one in the entire you tube teaching community can match your style of teaching and applying brain. Last part of space optimization really blew my mind.. Hats off Sir!!

    • @MadhavGupta-fi2tu
      @MadhavGupta-fi2tu ปีที่แล้ว +1

      why in tabulation base condition is from i=w[0] ?

  • @stith_pragya
    @stith_pragya 6 หลายเดือนก่อน +1

    UNDERSTOOD............one row optimization is an amazing thing.........Thank You So Much Striver Bhaiya for this wonderful video..........🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻

  • @shuvo9131
    @shuvo9131 2 ปีที่แล้ว +1

    My love for this series getting deeper everyday,
    thanks for for the last optimization, its amazing

    • @MadhavGupta-fi2tu
      @MadhavGupta-fi2tu ปีที่แล้ว

      why in tabulation base condition is from i=w[0] ?

  • @aryanyadav3926
    @aryanyadav3926 2 ปีที่แล้ว +2

    Really the space optimization using only a single row was wow, which I realised after dry running of course!

  • @anshulsomvanshi9483
    @anshulsomvanshi9483 2 หลายเดือนก่อน

    1D Array approach was mind-blowing !!
    As always, thanks for the great lecture !!

  • @aakashyadav8142
    @aakashyadav8142 8 หลายเดือนก่อน

    Your effort for optimization as tremendous . I have no word to praise and respect you .
    Salute you sri.

  • @amanbhadani8840
    @amanbhadani8840 2 ปีที่แล้ว +1

    One array optimization is just next level thing. This shows how deep you understand,exactly what previous values our code is using while computing our present value.This is only visible if we manually do a dry run in tabular form .

    • @MadhavGupta-fi2tu
      @MadhavGupta-fi2tu ปีที่แล้ว

      why in tabulation base condition is from i=w[0] ?

  • @dhruvbajaj5079
    @dhruvbajaj5079 ปีที่แล้ว

    Great video. First time I am able to understand tabulation and space optimization intuitively.

  • @ankita716
    @ankita716 หลายเดือนก่อน

    understood! you are an extra ordinary teacher and make everything doable for us as well. thank you so much

  • @adityahirwani1672
    @adityahirwani1672 2 ปีที่แล้ว

    Simplest explanation ever , and the way you had arranged the DP problems is really outstanding its makes every problem so simple. Thankyou 😊

    • @MadhavGupta-fi2tu
      @MadhavGupta-fi2tu ปีที่แล้ว

      why in tabulation base condition is from i=w[0] ?

  • @ugempireninjaaaaaahatori6755
    @ugempireninjaaaaaahatori6755 7 หลายเดือนก่อน

    the last concept was just like a thrilling and amazing part , love you striver.....soon we will meet

  • @koushalsharma7041
    @koushalsharma7041 2 ปีที่แล้ว

    Absolutely loved the idea of space optimization to a single array. Understood !

  • @gem13259
    @gem13259 9 หลายเดือนก่อน

    Understood!!!!!!!...Thanqew so much Striver u made concepts easy......space optimization with 1array was incredible💫

  • @sayakghosh5104
    @sayakghosh5104 2 ปีที่แล้ว +1

    Mind blowing space optimisation....Hats Off Bhaiya!!!! Understood!

  • @tonystark-oq3mm
    @tonystark-oq3mm ปีที่แล้ว

    Man that lecture was amazing from start to end ! The final space optimization that really was like icing on the cake ! Thanks striver Understood!

    • @MadhavGupta-fi2tu
      @MadhavGupta-fi2tu ปีที่แล้ว

      why in tabulation base condition is from i=w[0] ?

  • @drishtirai864
    @drishtirai864 4 หลายเดือนก่อน

    Understood !! The single array optimization was mind-blowing.

  • @ssshwanth
    @ssshwanth 2 ปีที่แล้ว

    Hi bro, before starting this series i had zero knowledge in dp and searched for lot of videos bt no one said right pattern, bt u did for space optimization ,tricks and explained why not greedy works?
    We will appreciate ur work
    Thank you
    Learner 😁

  • @user-oz2eu7rs8v
    @user-oz2eu7rs8v 6 หลายเดือนก่อน +1

    Best explanation.Just loved it Thanks a lot striver for making such series .✌✌

  • @AdityaKumar-be7hx
    @AdityaKumar-be7hx ปีที่แล้ว

    This was awesome! No one ever explained when can we go from the other end in loop. This is the best explanation.

    • @MadhavGupta-fi2tu
      @MadhavGupta-fi2tu ปีที่แล้ว

      why in tabulation base condition is from i=w[0] ?

  • @dadidivya8663
    @dadidivya8663 ปีที่แล้ว

    Wow, Doing this on my own, I knew I have got better. Always assumed knapsack to be very difficult. Now it is a piece of cake. Thank you Striver!

    • @MadhavGupta-fi2tu
      @MadhavGupta-fi2tu ปีที่แล้ว

      why in tabulation base condition is from i=w[0] ?

  • @AbdulKadir-bh3el
    @AbdulKadir-bh3el 2 ปีที่แล้ว +2

    Its been a year im learning DSA, Most of the time ive skipped this problem due to awkward expln but now i can't leave it.
    Thnxx man😇

    • @MadhavGupta-fi2tu
      @MadhavGupta-fi2tu ปีที่แล้ว

      why in tabulation base condition is from i=w[0] ?

  • @RohitKumar-dy2gc
    @RohitKumar-dy2gc 9 หลายเดือนก่อน +1

    loved your one array optimization technique❤❤

  • @logeshv2125
    @logeshv2125 หลายเดือนก่อน

    Striver, that's super cool logic for using a single row✨

  • @ajith4249
    @ajith4249 9 หลายเดือนก่อน

    Thank you striver. Solved by myself in Tabulization and memoization and space optimzation❣

  • @user-or7xr2mt3o
    @user-or7xr2mt3o ปีที่แล้ว

    This is by far the best video that I have watched on 0/1 knapsack...even though I was able to do recursion + memoization as well as 2 row space optimization on my own....this further optimization to one row blew my mind !! AMAZING

    • @takeUforward
      @takeUforward  ปีที่แล้ว +1

      Every video on TUF post 2021 will be the best version of all videos you see :P

    • @MadhavGupta-fi2tu
      @MadhavGupta-fi2tu ปีที่แล้ว +1

      why in tabulation base condition is from i=w[0] ?

    • @raxxpatt
      @raxxpatt 10 หลายเดือนก่อน

      @@MadhavGupta-fi2tu bhai chill kar!! ..kitni lega yaar uski .. itna dhundega tho bhagwan mil jayenge .. thand rakh thodi 😄😄

  • @hoordealer
    @hoordealer 2 ปีที่แล้ว +1

    Awesome bro. Such TH-camrs like you and other also are support for us. Thanks for your every video.

  • @suhartabanerjee9177
    @suhartabanerjee9177 2 ปีที่แล้ว +1

    Great Sereies bro. You are doing a great job. Gradually now I am able to build logic and write the code on my own. DP certainly started to look much more easier than before.
    Please continue this series and finish it up as quickly as possible. We all are counting on you and we know we will learn a lot from you.

    • @MadhavGupta-fi2tu
      @MadhavGupta-fi2tu ปีที่แล้ว

      why in tabulation base condition is from i=w[0] ?

    • @VishalKumar-lw3yh
      @VishalKumar-lw3yh 10 หลายเดือนก่อน

      @@MadhavGupta-fi2tu if we come to index 0 let's say the the weight there is 5, and the weight
      we can take is 3..so we will discard it any value which is lesser than 5
      now say if the weight we can take is 9..so from 5 to 9 we populate our dp table with val[0]

  • @MukeshKumar-cc3uh
    @MukeshKumar-cc3uh 4 หลายเดือนก่อน

    Understood ❤. The 1 array space optimization part was amazing, it unlocked one more part of my brain.😅

  • @travellercoder7298
    @travellercoder7298 2 ปีที่แล้ว

    Underrrrrrssstttttooood now seeing the length of string u can guess how much I loved this thnx man..

  • @RapartiChaitanya
    @RapartiChaitanya ปีที่แล้ว

    In Space Optimization, instead of prev, curr. We can use dp[(ind - 1) % 2]. Where the dp is of size 2 * target.

  • @tanujchaniyari6005
    @tanujchaniyari6005 2 ปีที่แล้ว

    I have seen so many DP series, but boy oh boy your videos are next level thank you so much Raj bhaiya

  • @radhakishoriiiiiiiiiii7348
    @radhakishoriiiiiiiiiii7348 7 หลายเดือนก่อน

    35:54 LOL
    Awesome walk through to the intuition for optimizations.. thanks striver

  • @ayushanand8926
    @ayushanand8926 3 หลายเดือนก่อน

    Amazed by the one-dimesional spaced optimzation

  • @lexeve5298
    @lexeve5298 10 หลายเดือนก่อน

    Amazing space optimization ever seen in Dynamic programming, these type of lectures motivates us to work hard, Thanks bro

  • @harshitabhatt4301
    @harshitabhatt4301 ปีที่แล้ว

    yes, 1d array optimization technique was amazing!!

  • @ankitaKumari-br1oc
    @ankitaKumari-br1oc หลายเดือนก่อน

    Wonderful, Knapsack was never this easy before 🤩

  • @paveshkanungo6338
    @paveshkanungo6338 8 หลายเดือนก่อน

    Understood! Space optimization is mind blowing🤯🤯

  • @aasthaaggarwal8909
    @aasthaaggarwal8909 2 ปีที่แล้ว

    The best ever explaination of DP present on Earth is yours.

  • @darksidekiller5300
    @darksidekiller5300 2 ปีที่แล้ว

    Understood Bhaiya

  • @dheerajsharma5492
    @dheerajsharma5492 2 ปีที่แล้ว

    Understood and love it striver. Thank you for this wonderful content.

  • @ONLYFORCF
    @ONLYFORCF 2 หลายเดือนก่อน

    really amazing video didnt find such video anywhere else

  • @DivyaKumari179
    @DivyaKumari179 หลายเดือนก่อน +1

    Thanku for this amazing series. And as always #UNDERSTOOD.

  • @KulvinderSingh-pm7cr
    @KulvinderSingh-pm7cr ปีที่แล้ว

    Gazab bhai, understood, only this video explains this single array approach that too so succinctly

  • @jazzgirl2358
    @jazzgirl2358 ปีที่แล้ว +1

    I wish you would take one more state for n so that we can handle case for empty subset with much more ease. i==0 will represent array as empty and for i=1to n, i-1 will represent the index.

  • @sayandey2492
    @sayandey2492 10 หลายเดือนก่อน

    Thief sitting and filling the DP table before starting picking up things is real savage !!!! 😁

  • @gaura-krishna
    @gaura-krishna ปีที่แล้ว

    The best part is,... I always learn something new that I don't learn anywhere else.

  • @subhadrosamaddar6336
    @subhadrosamaddar6336 หลายเดือนก่อน

    What the level of content! Hats off bhaiya for your effort.Thanks you a lot.I am also in the same college of you - JGEC. You are my motivation and spirit of learning coding.

  • @devnakum9297
    @devnakum9297 2 ปีที่แล้ว

    Understood Sir👍. Optimization using single array was just amazing !!!

  • @sangeetasharma8574
    @sangeetasharma8574 ปีที่แล้ว

    Amazing Explanation -understood the single row optimisation -Thanks Striver

  • @nagame859
    @nagame859 10 หลายเดือนก่อน

    just absolutely insane! the concept that we don't need to use the right ones 👌

  • @ayushagrawal3254
    @ayushagrawal3254 2 หลายเดือนก่อน

    You content is so so good. Understood very well.

  • @ayanghosh7635
    @ayanghosh7635 ปีที่แล้ว

    I just solved the problem all by myself.. all thanks to you bhaiya!! U r the best teacher i ve seen so far ❤️

    • @MadhavGupta-fi2tu
      @MadhavGupta-fi2tu ปีที่แล้ว

      why in tabulation base condition is from i=w[0] ?