Lecture 110: 0/1 KnapSack Problem || learn 2-D DP Concept || DP Series

Поделиться
HTML-код
  • Опубликовано: 28 окт 2024

Комментарии • 191

  • @muzammilaltafmulla
    @muzammilaltafmulla Месяц назад +2

    This is by far the best Knapsack video I've ever seen...

  • @shubhambarore5548
    @shubhambarore5548 2 года назад +25

    Before watching this video, I was very confused about the dimension of DP , whether to take 2D / 3D , now I feel comfortable with it, I appreciate your efforts for this free and Top-Notch content !!!

  • @hardikshukla4508
    @hardikshukla4508 Год назад +7

    Never seen such simple and more descriptive way to understand such a complex problem, Such DP videos are just awesome :)

  • @TheEleetcoder
    @TheEleetcoder 2 года назад +8

    The demagorgan of dsa no one can kill!! You are amazing!!

  • @brain1212
    @brain1212 Год назад +7

    The fear of dp is rapidly decreasing due to such great videos
    Thanks a lot and lot bhaiya
    Feeling lucky to have your videos for my preparation

  • @jayant2366
    @jayant2366 2 года назад +1

    bina bahut jada coding jane bhi agar aapki video se pahdo to bhayia pura pura samjh ata h.

  • @front-dive
    @front-dive Год назад

    bhaiiya jab aapne bola na left to right tb mere chehre pe ek smile thi or fir turant hi click kiya ki right to left se kuch nhi fatega. aapko sb pta hai kha kon bnda fas skta hai you are great teacher love you bhaiya 💖💖

  • @146_shashanks4
    @146_shashanks4 2 года назад +12

    I love the way u teach bhaiyaa still I have not watched this vedio due to my exams which starts from tomorrow but I can undoubtedly say it will be in next level I just came here to comment pls don't stop this dp series bhaiyaa I am literally depending on you once my exam completes I will resume watching your vedios bhaiyaa
    Lots of love from my side
    I am from Bangalore Karnataka

    • @peterpace3379
      @peterpace3379 2 года назад +13

      Address bhi de dete apna

    • @ytg6663
      @ytg6663 4 месяца назад

      Stop this bhaiya culture

  • @aniketkumar3218
    @aniketkumar3218 2 года назад +30

    Questions:
    1. 0/1 Knapsack
    2. Equal Subset Sum Partition
    3. Subset Sum
    4. Minimum subset sum difference
    5. Count of subset sum
    6. Target Sum

  • @sal2054
    @sal2054 2 года назад +12

    Happy Teacher's Day Bhaiya.Grateful for everything you have done for us.May Krishna bless you profusely.🙏🙏

  • @DPCODE72
    @DPCODE72 2 года назад +63

    Ohhhhhhh bhaiyyyyaaa, one thing that I would like to tell you that I'm not sure that I will place in Product based company whether yes or not. But honestly I have been following your each & every video on RUclips. So it will not matter that I will be placed or not but I'm sure that end of the knowledge I will make a character that will inspire to many students in upcoming time. Great thank you bhaiya!!. Just feel narvou or depressed 😔 nowadays!!

  • @TheEleetcoder
    @TheEleetcoder 2 года назад +8

    Thank You bhaiya !! I am solving all the questions you teach in your lecture and explain it my way and then upload the video on youtube! i want to try the teaching field as well. I even mailed you regarding your team (to be a part of your team.....hope you read it!)

  • @PoliticalTruth1
    @PoliticalTruth1 2 года назад +1

    Bhaiya apse padh ke bahut hi achha laga dil se apko thanks bolna chahta hu Q ki ap ke teaching style ka to hm fan ho gye hai
    Bhaiya plz is course ko total complete kijiye ga bahut ummid hai is course se mere future ke liye
    Once again thank you bhaiya ❤️

  • @ayushsoni3681
    @ayushsoni3681 3 месяца назад

    Last approach dekh kar toh maza hi aa gya bhaiya , thanks a lot !!!

  • @shreyashdubey5989
    @shreyashdubey5989 2 года назад +4

    ❤❤ DP looks simpler now , Lecture Completed... Keep going bhaiya👏👏

  • @believer-n3t
    @believer-n3t 2 месяца назад

    highly recommended video for knapsack. best video i have ever seen, can be further more better if you show the optimization by putting the value in dp.
    but i understand its time issue. ❤

  • @sandeeptottadi
    @sandeeptottadi 2 года назад +9

    Just needed DP. Thank you 💕

  • @jaysoni4180
    @jaysoni4180 Год назад +2

    consistency ++ ! and yes consistency is Underated!

  • @harshalpatil4496
    @harshalpatil4496 11 месяцев назад

    Great explanation. Glad that you covered all the scenarios which gives crystal clear clarity for the given problem statement.

  • @golubhattuk01
    @golubhattuk01 5 месяцев назад

    i didn't understatand the last 2 videos but this one amazing cleared all the doubts

  • @asifmondal7609
    @asifmondal7609 2 года назад +2

    At first... Thank You Very Much bhaiya.. cum sir! :)
    I don't know that if this much adventure was already present in this question how much I felt... But in this whole solution process by using all methods.... I enjoyed very much and learned a lot. During the whole hour... in every moment every point was clearly realized by your logic and describing. Thank you so much again sir

  • @Sahil1001
    @Sahil1001 2 года назад

    sir ji late cahl raha hu dheere dheere pahuchunga isme !! just bata raha hu ki aapka kaam best h !!!

  • @govindsuryavanshi6653
    @govindsuryavanshi6653 Год назад

    First I have completed all DSA series and now conclude this is Greatest ever DSA series to exists on youtube or paid courses. Your contribution will be remembered. You're God of DSA for us🙇‍♂ Thanks you.

    • @therealartist9
      @therealartist9 7 месяцев назад +2

      bhai tu bada khali aadmi hai yar

  • @agnivashil4130
    @agnivashil4130 Год назад +3

    It would have been better if how the 2D array got filled had been shown; otherwise, great explanation!

  • @beingoutofthebox8906
    @beingoutofthebox8906 2 года назад +2

    Thanku
    Explained the concept in a very easy way.

  • @rachit_joshi
    @rachit_joshi 2 месяца назад

    Thank You So Much BHRATA SHREE !!!!!!!

  • @Eng...1
    @Eng...1 8 месяцев назад +1

    Just amazing lecture 🎉😊

  • @prajaktabhalerao1239
    @prajaktabhalerao1239 Год назад +4

    Bhaiya, why have you returned prev[capacity] and why not curr[capacity]? n-1 denotes the last row right, which is curr.

  • @pramantomar822
    @pramantomar822 2 года назад +2

    Loving the series ❤️❤️❤️❤️❤️❤️❤️❤️

  • @samirkhandekar4678
    @samirkhandekar4678 3 месяца назад

    Thank you. But did you guys not find it overwhelming? So many concepts to grasp.

  • @vaishnavrushikesh4022
    @vaishnavrushikesh4022 2 года назад

    Bhai Gajab ka explain Kiya hai. Maja aa gaya.

    • @piyushgaur6975
      @piyushgaur6975 2 года назад

      bhai mujhe smjh nhi aaya yaar Bottom Aproach mein DP intialization smjh
      for(int j = 1; j

    • @vaishnavrushikesh4022
      @vaishnavrushikesh4022 2 года назад

      @@piyushgaur6975in initialisation, it is not weight[0]. It must be value[0].
      J= 1 to W means we are checking weight from 1 to W. dp[0][w] show that when we have one element than what kind of profit we get. If weight of 1st element is less than bag weight than we have to take first element so that time we get the profit of first first element.
      Ex : bag cap = 10kg
      1st element weight = 5kg
      Than
      dp[0][1] to dp[0][4] is zero
      And dp[0][5] to dp[0][6] is value[0].

    • @piyushgaur6975
      @piyushgaur6975 2 года назад

      @@vaishnavrushikesh4022 arey bhai thank you very much bhaii, mein bta nhi skta kitna pareshaan hogya tha m ...smjh hi nhi aara tha thanks

    • @piyushgaur6975
      @piyushgaur6975 2 года назад

      One thing I have to say that, In the initialization loop of bottom up approach
      for(int j = weight[0]; j

    • @vaishnavrushikesh4022
      @vaishnavrushikesh4022 2 года назад +1

      @@piyushgaur6975 correct but note one thing when you make dp vector thay you have to initialise all the elements to 0.

  • @zeroooo___
    @zeroooo___ Год назад +4

    I am having problem where you write the code of =>analyse the base case in solveTab( )
    Why you run for loop from weight [0] to capacity

    • @souvikmondal04
      @souvikmondal04 3 месяца назад

      You can write like below also -
      //for all index 0 and weight from 1 to max weight we need to take care
      for(int i = 1; i

  • @Kushal-p7i
    @Kushal-p7i 10 месяцев назад

    Nice, thnks for teaching different approaches ❤

  • @sanketharvande8773
    @sanketharvande8773 2 года назад +4

    Bhai pls make programs in java also.......💯pls bhai, it'll be helpful for more JAVA people including me 🙂

  • @jatinlodhi980
    @jatinlodhi980 Год назад +1

    bhiya prev = curr and curr = new int[capacity+1]

  • @anshumanacharya9812
    @anshumanacharya9812 10 месяцев назад +2

    Thank you so much bhaiya...
    But, how can somebody think of starting the loop from w = weight[0] to maxWeight in analysing the first base case?
    Please somebody reply if have any logic from the front, or how it would click if asked impromptu?..

  • @chinmaypanchal2521
    @chinmaypanchal2521 Год назад +10

    w = weight[0] kyu lagaya usi pe toh atka hun 28:40

    • @UtkarshSinha-ok5fg
      @UtkarshSinha-ok5fg 5 месяцев назад +1

      It actually doesn't matter if you start it with w=0 or w=weight[0], if you look at next if condition then....all values from w=0 till w

    • @kushaalrana
      @kushaalrana 3 месяца назад

      @@UtkarshSinha-ok5fg one more question why did 2d dp have n, w+1, why not n+1 and w+1

    • @UtkarshSinha-ok5fg
      @UtkarshSinha-ok5fg 3 месяца назад

      @@kushaalrana because for including W in the array we would need indexes from 0 to W and hence the required size of the array would be W+1,
      for n we don't have to use n+1 because the robber is carrying n items so an array of size n would do the job.

  • @shubham_jha
    @shubham_jha Год назад +1

    Babbar bhaiya!!

  • @ND-bm6im
    @ND-bm6im Год назад

    you are such a great great bhaiya we all are love you bhaiya so much

  • @raorao7329
    @raorao7329 4 месяца назад +2

    Jabse dp aur graph shuru hue hai tabse samajh aana kam ho gya bhaiya

  • @abhinavsinghal314
    @abhinavsinghal314 2 года назад +1

    Bro for greedy, graphs etc also we need roadmap similar to dp

  • @KhushiKavya-py1yj
    @KhushiKavya-py1yj 2 месяца назад

    consistency++

  • @sachinrathod8319
    @sachinrathod8319 Год назад

    last solution was fab💥

  • @Avez5
    @Avez5 2 года назад +1

    Present Bhaiya

  • @VishalKumar-ez2vj
    @VishalKumar-ez2vj 2 года назад

    dil garden garden ho gya ! 😃 Thanks alot bhaiya !

  • @therealartist9
    @therealartist9 7 месяцев назад

    some concepts which is not explained -> hameny dp initialization mai maxwieght kyu liya jabki ham index lete the , 2nd ->value aur capacity dono ki value change maar ri hia

  • @mdmasleuddin4992
    @mdmasleuddin4992 2 года назад +1

    Sir plz 40 lecture ke baad ka note upload kar dijiye

  • @ayushdube-e9s
    @ayushdube-e9s 4 месяца назад

    atleast one dry run would help everyone to grasp the knowledge quickly.

  • @khushboobuwade2932
    @khushboobuwade2932 2 года назад +1

    Bhaiya poori playlist kab tk bnegi ...ye Last video hai ya aur aage kitne months mai complete hoga course

  • @arvindmali5179
    @arvindmali5179 Год назад +1

    best

  • @VivekKumar-f7b3g
    @VivekKumar-f7b3g Год назад

    Bhaiya last wala line mast the left to right😂😂

  • @rashidhridoy2017
    @rashidhridoy2017 Год назад +3

    How can I pay my gurudakshina?

  • @siddharthambast7745
    @siddharthambast7745 2 года назад

    Brilliant Content

  • @9852963775aaa
    @9852963775aaa 2 года назад +1

    Bhaiya ab thoda confidence aa raha hai shayad kahi ache jagah lag jau.Thankyou bhaiya for this amazing content.

    • @piyushgaur6975
      @piyushgaur6975 2 года назад

      bhai mujhe smjh nhi aaya yaar Bottom Aproach mein DP intialization smjh
      for(int j = 1; j

  • @SajanKumar-ec2us
    @SajanKumar-ec2us Год назад +1

    Explain how to write for loop in base cases

  • @md_arfin_cse
    @md_arfin_cse 2 года назад

    Superb bro
    Best Best DSA course on RUclips.

  • @aniruddh2175
    @aniruddh2175 2 года назад +3

    Why do we initialize dp array with -1 while top-down approach (Memoization) and with 0 while bottom-up (tabulation)?

    • @vatsalshingala3225
      @vatsalshingala3225 Год назад

      you can do anything

    • @usernamewhatsoever4557
      @usernamewhatsoever4557 Год назад

      because -1 will never be an answer that will be computed for a subproblem
      so if array has -1 stored means this subproblems answer hasnt beeen computed and stored in array yet

    • @usernamewhatsoever4557
      @usernamewhatsoever4557 Год назад

      meanwhile in bottom up, vectors automatically initialize with 0 so you dont need to explicitly initialize with 0

  • @iteself_me
    @iteself_me Год назад

    138 ✅completed 👍Liked 12:07

  • @theoneyt999
    @theoneyt999 2 года назад

    ❤️🤞 thank you bhaiya

  • @lakshyabaliyan7917
    @lakshyabaliyan7917 2 года назад +6

    Bhaiya c++ DSA me leetcode par qus solve nhi ho rhe hai 😭

    • @DPCODE72
      @DPCODE72 2 года назад +6

      Don't worry, just keep trying & practicing!!

    • @technoakshay20
      @technoakshay20 Год назад

      Ab ho raha hai kya ?

    • @lofireverbz-wy7go
      @lofireverbz-wy7go Год назад +1

      @@technoakshay20 ab uski placement lg gyi bhai

  • @Kratikgarg
    @Kratikgarg 2 года назад

    bhaiya aapne jaise notes suru main dale the vese notes aapne sari videos ke bna ke kyun nhi daale please bhiya daal do isse hm log ko bahut help mlegi

  • @B-NikhilRichhariya
    @B-NikhilRichhariya 10 месяцев назад

    hash last smjhaa

  • @nishankdeep3084
    @nishankdeep3084 2 года назад

    thank you bhaiya

  • @namanpadiyar09
    @namanpadiyar09 4 месяца назад

    tough lagra bhaiya🥲

  • @keshavarya5999
    @keshavarya5999 2 года назад

    Bhayankar 🎉🔥

  • @vivan1852
    @vivan1852 2 года назад

    Thank you bhaiya , attendance done

  • @unboxtheuniverse5336
    @unboxtheuniverse5336 2 года назад +1

    Bhaiya abbb Continue Videos aayegi na 😃😃🔥

  • @swapnilgt
    @swapnilgt 6 месяцев назад

    In the tabular way, when analysing the base case (step 2), not sure why have we used "int w = weight[0]". Since we want to iterate from weight = 0 to weigth

    • @NNUK28
      @NNUK28 4 месяца назад

      in this case rows[0] all cols value will set as 0 means this weight can't fit on this bag

  • @SouravYadav-pb3xx
    @SouravYadav-pb3xx 2 года назад

    Maja aa raha hai

  • @acxd
    @acxd Год назад

    charging karte hue kya camera record nahi karta kya , ya in camera's ki battery alaga se nikal ke change hoti hai??

  • @vishalgarna4580
    @vishalgarna4580 Год назад +1

    Thoda samaj aaya 😅😅😅

  • @kingshukpal301
    @kingshukpal301 Год назад

    Good content but lack of explanation why what happened especially tabulation

  • @saadshakeel3348
    @saadshakeel3348 2 месяца назад

    Is there any benefit of memoization in knapsack problem as there is no overlapping sub problem in dry run.

  • @VishalGupta-xw2rp
    @VishalGupta-xw2rp 2 года назад

    Yeahhh 🔥🔥🔥.... Do you need any Web Development Intern... I will be really glad

  • @shachisinghal8856
    @shachisinghal8856 2 месяца назад

    sir, in some memo Q you start index from 0 and base case at n-1, in others from n-1 and base case at 0. Why this confusion? Can someone clear!!

  • @subhadeepchaki9529
    @subhadeepchaki9529 2 года назад +4

    In first loop why it start with w=weight[0] not w=0, i guess weight array is not given in sorted order. I tried using w=0 it's giving wrong answer. Can anyone explain please ??

    • @shashwatkumar6965
      @shashwatkumar6965 2 года назад +2

      no, bro. you can actually start with w = 0. only change is instead of checking if weight[0]

    • @kushaalrana
      @kushaalrana 3 месяца назад

      @@shashwatkumar6965 can you also clarify why is dp array starting from n,capcity+1 and why not from n+1, capacity+1

    • @shashwatkumar6965
      @shashwatkumar6965 3 месяца назад +1

      @@kushaalrana For defining the size of dp array always look at how you are calling the solve recursive function for the first time from your main code. Since solve is called with solve(n - 1, maxCapacity) therefore we need to have size n and capacity + 1 to store all the results. It's no harm in creating a dp array with n+1 as well, but the nth position will never be used since the all the elements are from index 0 to n-1.

    • @kushaalrana
      @kushaalrana 3 месяца назад

      @@shashwatkumar6965 Thank you so much❤️, that was very precise 🔥💯

  • @sagnikmodak4178
    @sagnikmodak4178 Год назад

    Thanks sir

  • @sukhjitsingh959
    @sukhjitsingh959 2 года назад

    Thanks for vedio sukhjit here

  • @studygainer5482
    @studygainer5482 Год назад

    completed

  • @rudrashankar62
    @rudrashankar62 2 года назад

    bhaiya videos roz upload kro

  • @prathamesh2906
    @prathamesh2906 2 года назад

    thanks for video

  • @RandomGuy-xq1hk
    @RandomGuy-xq1hk 10 месяцев назад

    Nice video 😇😇😇

  • @JohnSmith-uu5gp
    @JohnSmith-uu5gp Год назад +1

    Just Awesome!!!

  • @RashmiBajaj-mf3el
    @RashmiBajaj-mf3el Год назад +3

    Somebody please clear my doubt here!!
    In the solveTab method, in base case analysis
    why is the loop going from wt[0] to capacity ? Why not from 0 to capacity?
    Please help me understand this, anybody..

    • @RashmiBajaj-mf3el
      @RashmiBajaj-mf3el Год назад

      @CodeHelp - by Babbar

    • @kostubh
      @kostubh Год назад

      So here is the explanation-
      Here dp[i][j] will give you the value of the ith index with j weight, so now for the base case we are considering the 0th index only, which will have the wt[0] initially.
      Aise socho, hum uska weight increase kar rahe hai, aur hum tab tak increase kar sakte hai, jab tak vo capacity se jyada na ho jaaye.

    • @abhinavarya7752
      @abhinavarya7752 Год назад +1

      Kya ho if weight[0] is greater than capacity?

  • @ishansaxena6631
    @ishansaxena6631 2 года назад +1

    Last wala optimization bilkul samajh nahi aya

  • @manavrollno.2314
    @manavrollno.2314 2 года назад +1

    Now the video length is op

  • @yashraghuwanshi7710
    @yashraghuwanshi7710 6 месяцев назад

    sir yeh lecture ka explanation bilkul sahi nhi lga vector m n(row hai kaise ptaa) or maxweight(column hai yeh kaise ptaa chla) maxweight+1 he kyun kiya or tabulation for lopp condition base kaise hua or achese nhi smjhaya sir please explain to me

  • @taneyasoni
    @taneyasoni Год назад

    why are we initializing include=0 and exclude=0 everytimme we call the function.

  • @anandkumarrohal9168
    @anandkumarrohal9168 2 года назад

    thanks 😁😁

  • @glaciar_range3270
    @glaciar_range3270 8 месяцев назад

    respect++

  • @_nisarg_shah
    @_nisarg_shah 2 года назад

    Reach++

  • @appsuniverse9976
    @appsuniverse9976 2 года назад

    very good explanation about knapsack problem

  • @harishkumar2107
    @harishkumar2107 2 года назад

    Love babbar sir you are best 🔥🔥❣️

  • @thatindianboy2817
    @thatindianboy2817 2 года назад

    Bhai ye jo tum call back kr rhe the (recursion- 2d)tabulation mein samjhane ki bjae, uska link to at least daal dia kro. Kewal code dekhna hota to idhr kyu aata bro

  • @prashantpandey6078
    @prashantpandey6078 2 года назад

    Great timing Love Bhaiya... Thanks

  • @nayanjaiswal
    @nayanjaiswal 2 года назад

    Present sir

  • @arzitmahajan7703
    @arzitmahajan7703 2 года назад +2

    Can we implement recursive approach left to right and make the base case if(index ==n-1){....}. If not can anyone please explain why?

    • @ramanjangra7465
      @ramanjangra7465 9 месяцев назад

      YES we can do in that way also

    • @ramanjangra7465
      @ramanjangra7465 9 месяцев назад +1

      gfg ans :
      int solve(int w, int i, int wt[], int val[],int n, vector&dp){
      if(i==n-1){
      if(wt[i]

  • @imvivekkushwaha
    @imvivekkushwaha Год назад

    Why not 5 of one weight will also be 25 which will be greatest.

  • @KratosProton
    @KratosProton 2 года назад

    Great explaination

    • @piyushgaur6975
      @piyushgaur6975 2 года назад

      bhai mujhe smjh nhi aaya yaar Bottom Aproach mein DP intialization smjh
      for(int j = 1; j

  • @sushant1363
    @sushant1363 2 года назад

    Plz upload SQL Lecture asap.