5 01 Knapsack Top Down DP

Поделиться
HTML-код
  • Опубликовано: 8 сен 2024
  • 0-1 Knapsack Problem solution using Tabulataion Method.
    TOP DOWN APPROACH
    Example:
    Given weights and values of n items, put these items in a knapsack of capacity W to get the maximum total value in the knapsack. In other words, given two integer arrays val[0..n-1] and wt[0..n-1] which represent values and weights associated with n items respectively. Also given an integer W which represents knapsack capacity, find out the maximum value subset of val[] such that sum of the weights of this subset is smaller than or equal to W. You cannot break an item, either pick the complete item, or don’t pick it (0-1 property).
    PROBLEM STATEMENT LINK:www.geeksforge...
    Playlist Link: • Dynamic Programming | ... .
    ------------------------------------------------------------------------------------------
    Here are some of the gears that I use almost everyday:
    🖊️ : My Pen (Used in videos too): amzn.to/38fKSM1
    👨🏻‍💻 : My Apple Macbook pro: amzn.to/3w8iZh6
    💻 : My gaming laptop: amzn.to/3yjcn23
    📱 : My Ipad: amzn.to/39yEMGS
    ✏️ : My Apple Pencil: amzn.to/3kMnKYf
    🎧 : My Headphones: amzn.to/3kMOzM7
    💺 : My Chair: amzn.to/385weqR
    🛋 : My Table: amzn.to/3kMohtd
    ⏰ : My Clock: amzn.to/3slFUV3
    🙋🏻‍♀️ : My girlfriend: amzn.to/3M6zLDK ¯\_(ツ)_/¯
    PS: While having good gears help you perform efficiently, don’t get under the impression that they will make you successful without any hard work.

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

  • @kushmidedhia7175
    @kushmidedhia7175 4 года назад +913

    Hey very good explanation, I agree on the comment that direct tabulation approach is not very intuitive to normal human mind, we have to build up the solution starting from recursion and memoization. Just one small comment, the tabulation approach is not top-down but bottom-up. It is called bottom-up, because we start the solution from base case (initialize matrix using base case) and build the solution to the top (t[n][w] in this case).

    • @TheAdityaVerma
      @TheAdityaVerma  4 года назад +472

      Oh yeah. of course I am glad you pointed it out. I messed up, those two terms have always been confusing to me !! 😅However our solution is still correct af, I am glad names don't effect the way you do things !! Let's just call one Memoization and the other Tabulation to avoid confusion. What I did in this solution is Tabulation. Thanks for pointing is out tho !! Keep watching and share ✌️

    • @anmol-gupta
      @anmol-gupta 4 года назад +149

      @@TheAdityaVerma I'd suggest adding a video after the introduction of the playlist that explains the difference between top-down (memoization) and bottom-up (tabulation). You can mention it in that video that whenever you say "top-down" in the following videos, you actually mean "bottom-up" or "tabulation". It's important that no one learns a wrong thing. Other than that, your videos are very helpful. :)

    • @deepamgupta8011
      @deepamgupta8011 4 года назад +60

      The videos are good, but even a minor mistake in standard terms also may lead to failure no matter the explanation is very good. You ought to add a frame at the start of each video that wherever you refer top-down, it is actually bottom-up, else, people will start losing faith. My intention is not from any means to hurt you, but since, your explanation is good, you need to be full-proof.

    • @stark_mark1107
      @stark_mark1107 4 года назад +46

      @@TheAdityaVerma So the recursive solution was top-down approach as we started at the top and kept making recursive calls until we reached the base case and then started returning values while the tabulation one was bottom up as explained in the comments, right??

    • @saurabhmarpadge7498
      @saurabhmarpadge7498 4 года назад +14

      @@stark_mark1107 Ya exactly.

  • @vibhuagwl
    @vibhuagwl 4 года назад +164

    I am working in IT for the last 7 years I have tried many tutorials for data structure and algorithm but no one explained like you. I really appreciate your effort. Please make the videos topic-wise from basic it can be paid or free.

    • @TheAdityaVerma
      @TheAdityaVerma  4 года назад +32

      Thanks a lot brother !! I am glad you liked it !!

    • @coolbuddy8386
      @coolbuddy8386 4 года назад +10

      I also felt the same way, thank you so much for time and effort Aditya Bhai. As you said all the youtubers just explained the tabular method but no one taught the same u r teaching i.e converting recursion into tabular method. hats off for your explanation and ideas. Keep uploading such problems and videos I am loving it.

  • @snehilsinha4689
    @snehilsinha4689 3 года назад +22

    I tried learning this from hell lot of YT channels like Tushar, Jenny, Apna College, Anuj Bhaiya, even MIT Open Courseware. One word, all are trash and I could understand nothing from them! Only a true coder like you who actually works in a company and who has grinded so hard to achieve it can explain this with such clarity. Tysm brother! 💓

  • @kritikatripathi806
    @kritikatripathi806 4 года назад +167

    This is just to let you know that this is the first time when someone has explained me "how to code" with such clarity! I am really very amazed and motivated today because of this video playlist.

    • @TheAdityaVerma
      @TheAdityaVerma  4 года назад +23

      Glad it helped you !! Please consider sharing the content with your friends or college to help this channel grow !!

    • @ankushroy919
      @ankushroy919 4 года назад +4

      @@TheAdityaVerma bhaiya yahi to prblm hai market me itna competition hai ki share karte wakt dar lagta hai actually nahi kar pata hu baki likes or comment to milega

    • @user-stevegjffuhdry
      @user-stevegjffuhdry 3 года назад

      @@TheAdityaVerma will definitely! keep on posting, love the vids

    • @buzzfeedRED
      @buzzfeedRED 3 года назад

      @@TheAdityaVerma Excellent Explaination. But in the GFG knapsack problem. The memoize solution is not accepting, while the top-down is accepted. There is a time limit exceeded error.

    • @ankitbhardwaj7363
      @ankitbhardwaj7363 3 года назад

      @@buzzfeedRED 0/1 knapsack or unbounded knapsack ?

  • @nehaagarwalla9004
    @nehaagarwalla9004 Год назад +17

    Bro I am a 15 years experience engineer.. your explanation and determination to make everyone understand this topic hits hard

    • @muditkhanna8164
      @muditkhanna8164 8 месяцев назад +5

      after 15 years why are you here for dp tutorials. i mean dp is basically caching. you might've already knew that.

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

      @@muditkhanna8164 YOE?

  • @jameysiddiqui6910
    @jameysiddiqui6910 3 года назад +120

    This video is great having great explanation, having two minor mistakes. 1) Top down is actually bottom up. 2) At time 29:37 it should be be T[n-1][w-wt[n-1]]

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

      yes exactly

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

      Agreed

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

      Why taking dp[n+1][w+1] for what that +1 please resolve my doubt

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

      @@bokkamanideep9893 The size of value or weight array varies from 0(no element) to n (all elements) . So we have to select the size of tabulation table t[n+1][W+1] so as to accommodate all possible combinations from 0 size and weight to n size and W weight

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

      Can you please explain why it would be w-wt[n-1] ? Isn't the second condition for the case where we are not selecting any element? When we are not selecting anything, what weight are we subtracting?

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

    I might be wrong but this technique is called Bottom-Up (Tabulation) and the technique you taught in last video is called Top-Down (Memoization) technique.
    I have learnt basic concepts from your tutorial and it obviously helped me to understand DP fundamental concept.
    Thanks bro for your skills to share with us.

  • @shubhanshusaxena1232
    @shubhanshusaxena1232 4 года назад +48

    this is called as TEACHING Dynamic Programming!!
    great work Aditya! :)

  • @capone2676
    @capone2676 2 года назад +26

    Why cant I double like? This deserves a thousand likes. You opened a whole perspective of DP for me.
    Using recursion first to explain and then coming to bottom up approach was a stroke of masterpiece. I've always wondered how to solve DP with tabulation but this DP series is a life saver.

  • @ClassyKSC
    @ClassyKSC 3 года назад +11

    Didn't realize the 40 minutes were over till you said that "ab aapko samjh aa gaya hoga". That's how well you taught.

  • @BHARATKUMAR-dk1ij
    @BHARATKUMAR-dk1ij 3 года назад +16

    First time i have seen someone connecting recursive code and tabular code like this, your method of teaching is just amazing.

  • @damercy
    @damercy 4 года назад +44

    In my 3rd year now, and till date I've tried to learn from so many different resources but nothing like these videos. A genuine thank you from the bottom of my heart for keeping shit real and free. Stay the same when you hit those subscriber milestones on YT because you will. And soon! ✌️💯

    • @yogeshyts
      @yogeshyts 3 года назад +1

      placement hui ky?

    • @damercy
      @damercy 3 года назад +6

      @@yogeshyts Haan bhai, 10LPA

    • @yogeshyts
      @yogeshyts 3 года назад

      @@damercy company?

    • @damercy
      @damercy 3 года назад +1

      @@yogeshyts It's an early stage startup man. :)

    • @damercy
      @damercy 3 года назад

      @Adarsh Chaurasia Hey thanks! :)

  • @Learner010
    @Learner010 4 года назад +4

    at 29:44 you take one time i as W and j as n while taking maximum .. completed 5 video and you explained very well..Pure Gem

  • @ramankumar9856
    @ramankumar9856 4 года назад +5

    I am a student in IIT , was finding it difficult to solve it many youtubers just doent tell us why we created table why we put t[i][j] = max something , but after listening to this one video whole Dynamic programming is looking easy kudos to the person , am a fan of you now

  • @kush-cp8kc
    @kush-cp8kc 2 года назад +3

    BROooo ....I dont know how to thank you ....I was really looking for this exact way of teaching ... and yesterday only my senior suggested me from IIT Guwahati to follow you ...and i wasn't able to sleep after seeing the way and quality of content you have provided ....i was so eager to learn and watch ....thank you so much , really .

  • @wholeegg
    @wholeegg 4 года назад +268

    One day I'll succeed in spinning pen like you.

    • @meenalagarwal4516
      @meenalagarwal4516 4 года назад +18

      it took me entire 11th and 12th XD

    • @blasttrash
      @blasttrash 4 года назад +42

      I can spin using both hands :P Thats the only thing I learnt during IIT JEE preparation. Of course its not enough to get into IIT lol :P

    • @Lime-rr6te
      @Lime-rr6te 4 года назад +3

      practice jaari hai bhai

    • @0anant0
      @0anant0 4 года назад +7

      There is a pen available that has spherical weights that move towards the end to create centrifugal force -- it makes spinning very easy. Its called, (what else) spinning-pen. There is another spinning technique where you pass the pen between all the fingers -- check it out in the 'classroom training' scene in TopGun. Who knows what I am talking about?

    • @amansinghgautam9578
      @amansinghgautam9578 3 года назад +1

      @@0anant0 you can spin any pen lol

  • @JyotiSharma-dm8ls
    @JyotiSharma-dm8ls 2 года назад +3

    It's easy to find good developers out there but hard to find a good teacher. Paper pen approach is best to connect with the audience, in making them understand why something is being done and what is the thinking process to approach a problem. There could be minor mistakes here and there in what you have explained (my observations, based on the comments other viewers have left) but if the viewers can pickup on those means you have done a great job already in developing their thinking and they are following along with your explanations and thats what a teacher does :) . You have reminded me of college days where friends just used to discuss and solve problems using our basic tools -- pen, paper and friendliness of language.

  • @jayparekh1992
    @jayparekh1992 3 года назад +1

    i have spent more than 4 months to only understand DP, But I must say that what you have taught in 4 videos, if i had see it earlier it will save my 4 months. very good explaination.

  • @himanshugupta7010
    @himanshugupta7010 3 года назад +7

    Bro noone literally noone has this level of understanding . the way you explained it was way better than anyone out there . in my case I never studied DP from any where 'coz I was afraid but now I am damn confident to solve any problem because now I know how to approach the problem . thank you so much bro .. and a huge respect to you . Aditya Verma OP

  • @jasmeen2541
    @jasmeen2541 4 года назад +13

    Hands down!!!🙌🙌 You're the BEST teacher ever!
    No one has ever explained why of every single thing in DP, and you've done that ❤

  • @mastermind82134
    @mastermind82134 4 года назад +539

    bro why did u stopped uploading : ( , want series on graphs and advanced data structures too . your teaching is friendly , like we teach each other in hostels : ).

    • @sarthakpal8231
      @sarthakpal8231 4 года назад +53

      that hostel point was so damn relatable xD

    • @mrsukki8158
      @mrsukki8158 3 года назад +1

      He is dead bro 😭

    • @AbhishekKumar-im2xd
      @AbhishekKumar-im2xd 3 года назад +52

      @@mrsukki8158 stop spamming fake news

    • @Aks-47
      @Aks-47 3 года назад +24

      @@mrsukki8158 tera baap hoga, aditya verma nahi

    • @shaikfahim1232
      @shaikfahim1232 3 года назад

      @@mrsukki8158 aisa nahi hosakta

  • @AlbertoRodriguez-oe6jo
    @AlbertoRodriguez-oe6jo 2 года назад +147

    Code for all 3 approaches: Recursion => Memoization (Top down) => DP (Bottom Up)
    //1. Recursive Approach
    int knapSack(int w, int wt[], int val[], int n)
    {
    //Base Case
    if(n==0 || w==0) return 0;

    //Choice Diagram Code
    //1. Choice to include item or not
    if(wt[n-1] w){
    return 0 + knapSack(w,wt,val,n-1);
    }
    }
    //2. Memoize above recursive code (top-down)
    int knapSack(int w, int wt[], int val[], int n){
    vector t(n+1, vector(w+1, -1));
    return fun(w, wt, val, n, t);
    }
    int fun(int w, int wt[], int val[], int n, vector& t)
    {
    //Base Case
    if(n

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

      In Memoization why your code is giving the wrong input when the vector t is declared globally?

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

      is'nt it v[i] intead of v[i-1]

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

      @@anonymous63066 No bcuz we are checking for the wt[] array....And it starts from 0 index. Here indexing for the matrix is one more than that of the input array.Hope you get it.

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

      Can I please know why we require second else? when in If only we have the same statement?

  • @arindamdas3464
    @arindamdas3464 3 года назад +7

    Hands down the best explanation on DP. You are helping those who cant afford to join expensive courses online. Keep it up brother !! Thanks !!

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

    Thank You So Much Brother.I Don't Think Anybody else is teaching the Crux of Dynamic Programming So well!Your Videos are Valuable for Beginners!

  • @kalagaarun9638
    @kalagaarun9638 4 года назад +5

    pehli baar top down ka matrix bana ke use kata nhi 😅😅
    kudos to your effort, sir !! 🙌🙌

  • @agarwalaadi99
    @agarwalaadi99 3 года назад +7

    God level explanation brother !!! I was so afraid to start DP from much time. But when I started watching this playlist, it was so effortless for me to understand it . You made my day sir :) God bless you !!

  • @vijaypalmanit
    @vijaypalmanit 3 года назад +4

    I could learn and master recursion just because of you, otherwise I was always afraid of it, thanks a lot for your effort, couldn't learn things in college due to my health issue, but learning now and your videos are helping a lot, I am having 10 years of experience in IT.

  • @debbh274
    @debbh274 4 года назад +15

    Honestly, even if you pay a lot of money, you wont find the clarity with which you are explaining. Thoroughly enjoying it. Great work....Try making your videos in English also, your viewership will climb 10 folds...Also, your videos shows the huge number of hours you grinded to gain the clarity with which you are explaning. Great work and thanks a lot.

    • @TheAdityaVerma
      @TheAdityaVerma  4 года назад +4

      Thanks a lot for such a great comment brother. You made my day !! ❤️ Do share !!

  • @mohitsoni4352
    @mohitsoni4352 3 года назад +3

    Amazing explanation, I m final year student from tier3 college. I was shit scared with coding rounds as our teachers hv nvr taught us these things. Our clg placemnt was limited to Infosys TCS, finally after watching your videos I hv gained the confidence to try for Product based companies. I will surely meet you in person once Im placed in one of those companies. Love your work bro, please keep uploading videos these are really really helpful for students like me. Thank you so much.

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

    So far I liked your way of approach ...the great part about your video is that you show one way of approach and than to counter that you show other along with the reason of chosing the later one....it's builds up logic very effectively....will make effective use of whole playlist.
    Thanks sir 🙂

  • @llliiilll3624
    @llliiilll3624 4 года назад +76

    The initialization part can be done in O(n) instead of O(n*w).
    Use one for loop (from 0 to w) to set t[i][0] = 0 and another for loop (from 0 to n) to set t[0][i] = 0.

    • @Rajat-Sharma1
      @Rajat-Sharma1 3 года назад +3

      haa but woh abhi main nahi hai bhai, main hai yeh DP😂😂

    • @daisychain8011
      @daisychain8011 3 года назад +4

      You're 100% correct though the rest of the algo is O(n*w) anyway so it doesn't really matter Asymptomatically

    • @sanjayjoshi8807
      @sanjayjoshi8807 3 года назад

      bro does it matter if I write outer loop for W and inner loop for N ???

    • @jaydalsaniya6986
      @jaydalsaniya6986 3 года назад +3

      Ab ate hai yeh log , jo padhane vale k samne usko sikhate hai .

    • @amishasingh4606
      @amishasingh4606 3 года назад +1

      kuch bhi...isse khaali 1st row and 1st column hi initialise hoga

  • @immrhrr
    @immrhrr Месяц назад

    after watching this video,I feel like ab toh apun hi dp ka bhagwan hai
    thankyou so much ,I am able to visualize everything about memoisation and tabulation now

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

    The amount of efforts put in explanation is commendable!
    Thanks a lot sir!

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

    Hi, great videos on DP. But I think tabulation, that is deliberately filling the table from the most solvable(or smallest) problem is the bottom-up approach. the backtracking with memo/caching is Top down, where we take the entire problem and keep hammering on it till it is broken into smallest solvable pieces and cache results for reuse

  • @ajayraj1
    @ajayraj1 3 года назад +7

    This is Epic 🙌, thanks alot sir for this

  • @pavanala2200
    @pavanala2200 4 года назад +3

    One of the Best dynamic programming course.. ever❤️❤️

  • @kumardivyanshu7327
    @kumardivyanshu7327 3 года назад +1

    Finally, I understood the lines of code. Earlier, I was getting an error.
    Thanks!

  • @blue_jerry
    @blue_jerry 4 года назад +162

    at 29:30 in the bottom-up approach instead of t[w-weig[n-1]][n-1] it should* be t[n-1][w-weig[n-1]].

    • @ankitsagar8379
      @ankitsagar8379 4 года назад +7

      Rasik Mahajan was waiting for this comment

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

      correct! Got me confused. Now it's all clear

    • @tomy7424
      @tomy7424 4 года назад +3

      Right, He should be more focused when writing code, I know it's easy mistake to make but we can't doubt him as well and start thinking to our self why is that.

    • @0anant0
      @0anant0 4 года назад

      This reminds me of dfs grid problems where instead of considering mx[r][c], they consider mx[c][r]. (mx = matrix, r = row, c = col). Has anyone seen this?

    • @saketsrivastava4953
      @saketsrivastava4953 3 года назад +1

      I was searching for this comment , I was confused too -_-

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

    Great Lecture on DP. Thank you very much. I am a newbie to DP but I have idea of other DS and recursion. I thought that DP is gonna be tough, but you made it easier for us. The way you approach a DP problem is awesome. I will remember your each and every words.
    DP jaisi h waisi likhoge to DP ka solution likh loge.
    Never directly start with tabulation.
    DP is enhanced recursion.
    Agar recursive calls me tree bann rha h aur overlapping subtree dikhe to DP lagega. Aur question me optimal pucha hoga

  • @lakshmisravyaharivanam6045
    @lakshmisravyaharivanam6045 4 года назад +4

    I was searching for such a RUclips channel on dynamic programming that would help me think how to think and I am glad that I found your channel.. More power to you !!!

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

    best DP explanation till date either on free platform or on paid courses. :)

  • @tushargarg6359
    @tushargarg6359 4 года назад +8

    You are one of the greatest RUclipsr for the learning data structure. I was having a lot of difficulties understanding the recursion. Now a concept is quite clear. I think you should start your startup similar to algoExpert. You have great potential to explain everything which no one has. Other people just discussed solution but you discussed how to reach that solution. Could you please start the videos for "FAANG" companies? Complete tutorial. I will never mind taking a paid membership for it. I solved more than 50 problems in recursion but no one tells about the choice diagram. Please let me know how did you learn those things? Did you refer to any book?

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

    Finally someone who is teaching how to code a solution , rather than just telling the solution most of the youtubers and all my university professors just show the algo and don't give a damn about code , I am ready to pay for a course of such caliber

  • @purandarparitosh
    @purandarparitosh 4 года назад +6

    just one word bhaiya, just one:
    BRILLIANT!!!!

  • @ujwalsingh2636
    @ujwalsingh2636 3 года назад +1

    U r too good man... I have viewed most of the utube videos on dp but no one has xplained in so much depth.. U have my respect🙏

  • @devrajsinghshekhawat6617
    @devrajsinghshekhawat6617 4 года назад +4

    Fadd explanation hai bro.Your concepts are crystal clear, recursion par bhi playlist upload krdo brother

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

    bhai kya he bolu .majja he aaaa gaya ,10 times batter than college professors. recursion sikhane ke kiye eek video series bana do pls.

    • @TheAdityaVerma
      @TheAdityaVerma  4 года назад

      Thanks brother, Do subscribe and share, that keeps me motivated to do more !! and yeah its in my to-do list.

  • @curiosity9861
    @curiosity9861 4 года назад +5

    Everything u taught in this video is on point love it🔥🔥🔥🔥.

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

    Bro.... Really from my heart.... I thank you!. I have not been able to pass coding rounds due to questions in DP. I really feared. But the way you have explained.. just awesome!. Please go on!... Thank you! :)

  • @suvammondal698
    @suvammondal698 4 года назад +3

    You madee brave enough to encounter Algorithm and coding ❤️

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

    bruh Dil se thank you...You made things crystal clear in one go. way of explaination is also good. Hope to complete this playlist in 10 days.

  • @akshatjain6854
    @akshatjain6854 4 года назад +5

    Superb Bhaiyya while other youtubers are just making us mug up the code, you came up as a live saviour! Keep uploading. Also can you please make videos on general topics like how and where to study theory subjects, how to clear online test etc. It would be really helpful

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

    The best among the ones which exist...Explaining such a hard topic in a very simple manner. Hats off

  • @Ji-yoon
    @Ji-yoon 4 года назад +4

    Thanku so much for this amazing lecture.......!!!!!!

  • @084_sakshamgupta3
    @084_sakshamgupta3 20 часов назад

    i -> n and j -> w please take care of that, well explained thank bro

  • @PritamKarmakar
    @PritamKarmakar 4 года назад +3

    Amazing bro, so easy to follow. Keep rocking. Felt like I'm in my college days, some of my topper guys explaining me :)

  • @vijaychander2177
    @vijaychander2177 4 года назад

    Bhai alag level pe samja rahe ho. Most of the people don't understand how to teach. This is the perfect example of how one should teach anything.
    Thanks please keep the work and continue uploading videos

  • @suvodeeepbiswas6360
    @suvodeeepbiswas6360 4 года назад +4

    We are just awesome ..Lot of respect and lot of love to you sir❤️

  • @atanupaul1490
    @atanupaul1490 3 года назад +1

    Best explation of 0-1 knapsack in youtube
    It helps me a lot..😊😊😊

  • @jainlokesh318
    @jainlokesh318 4 года назад +4

    Great effort by u Man....Thanks a ton..!!!
    Waiting for the recursion playlist to be uploaded...I request you to please do it asap..
    Till then if you can recommend any material to ace recursion would be a great help :)

    • @TheAdityaVerma
      @TheAdityaVerma  4 года назад +4

      Will upload more video in the month of may !! Till then keep on sharing and help this channel grow + that keeps me motivated to make more videos !! ✌️❤️

  • @SunilSahu-li4cy
    @SunilSahu-li4cy 4 года назад +1

    well explained by you sir. A few days ago I have seen the solution of knapsack in algoexpert ds algo series. At first time I couldn't able to understand what and how the things are going because the problem was started itself from top down approach and today you have cleared my all doubts and the multiple solutions of it. I'm very thankful to you. 🖤

  • @GAURAVSINGH-hu3qp
    @GAURAVSINGH-hu3qp 4 года назад +5

    bro ur just too good

    • @TheAdityaVerma
      @TheAdityaVerma  4 года назад

      Thanks brother, share to help this channel grow !!

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

    This was so easy to understand. You made this scariest topic easy. Thankyou so much sir for this tutorial 😀😀🙏🙏

  • @gandharavkatyal822
    @gandharavkatyal822 4 года назад +3

    Hi bro,
    Great initiative.
    Please make videos on graphs as well :)
    It will be a great help.

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

    You are doing god's work. Very thankful to you. You tell us what we are trying to do fundamentally, which make it easy and quick to understand as compared to using definitions and bookish language.
    edit: I find it better to initialize value[] and wt[] arrays to n+1. this way there is no confusion in indexing it t[][].

  • @vivekagarwal4853
    @vivekagarwal4853 3 года назад +3

    Hi Aditya, Thanks for the amazing explanation but I think at 37:26, in the 'if' condition, we should reduce the weight of the bag with previously filled item while comparing the current item's weight like 'wt[i - 1] < weightOfbag - t[i - 1, weightOfbag]'.

    • @komaldeepsingh6356
      @komaldeepsingh6356 3 года назад

      Yes... I also noticed same

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

      no, it's not required, the current item's weight that is wt[i-1] is being compared to the jth value at that time, that is the current weight the bag or knapsack is holding.

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

    thanks a lot bro i am really loving the series.....I cant express how i am feeling after understanding everything

  • @anirudhlok2047
    @anirudhlok2047 4 года назад +5

    Hi Aditya,
    I had one question, how does replacing n with i and W with j work? because we check from end of array if the item's weight is < W ie (wt[n-1]

  • @murtuzashareef7906
    @murtuzashareef7906 4 года назад +1

    200% right. Nobody could explain like this. Hats off to you man!!

  • @amitgohri1622
    @amitgohri1622 4 года назад +3

    aren't you mistaking iterative solution saying it top-down which rather should be bottom-up ?

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

    God level explanation. All doubts are cleared. Please make a playlist on graph.

  • @muskangoel897
    @muskangoel897 4 года назад +3

    Is there any specific reason you took t[n+1][w+1] and not t[w+1][n+1]?

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

    i never ever thought i would be able to understand tabulation(bottom-up solution) but its all becuz of you, i got this .thanks alot man

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

    bhai aap kaise samjaathe ho ..gajab hai ... I have seen multiple videos on DP and mostly they just repeat the existing solution, but the way you mapped recursive to top-down is just amazing. I always struggled to find the top-down but never realized there is one-one mapping with recursive

  • @joshiadvait8
    @joshiadvait8 4 года назад +9

    Bhai recursion sikha do acche se ek bari....... fir DP halwaa lagegi

    • @TheAdityaVerma
      @TheAdityaVerma  4 года назад +6

      Will be uploading more videos in may till then keep sharing to help this channel grow + thats motivates me to make more videos !! ❤️✌️

    • @anikettatte7408
      @anikettatte7408 4 года назад

      @@TheAdityaVerma Bhaiya ..in desperate need of a playlist on Recursion..!! Love your work

    • @ritiksingh-dq2gs
      @ritiksingh-dq2gs 4 года назад

      Make video on dp for grid

  • @vivekverma4012
    @vivekverma4012 3 года назад

    i switched to your next video but suddenly i realised that i need to say thanku for your amazing explanation and great efforts.

  • @pruthvirajk6019
    @pruthvirajk6019 4 года назад +45

    Move on

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

    I usually don't hit like button on much videos,but you have to hit like in all his videos,they all are so good

  • @vishalchincholi4490
    @vishalchincholi4490 3 года назад +12

    THIS VIDEO SHOULD BE RE-TITLED AS "BOTTOM UP APPROACH" WHICH IS TABULATION.

    • @Ganeshsp1
      @Ganeshsp1 3 года назад +1

      This was what I too was wondering as this is Bottom up approach as the subproblems are solved first and then we go to the top to solve the main problem.

    • @jaydalsaniya6986
      @jaydalsaniya6986 3 года назад +1

      Here Bottom Up Approach ko sikha ke , he has tried to explain that top down mein bhi vahi kara ja sakta hai .And this is top down only.

  • @SanthoshKumar-dh9zg
    @SanthoshKumar-dh9zg 2 года назад

    Hatsoff to your coding experience and joting down points to convert one method to another. Thanks for sharing these points.

  • @AshishTiwari-cr2uj
    @AshishTiwari-cr2uj 4 года назад +44

    I am one of those jinka "recursion hi strong nai h"

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

      bhai karte rahe kosish geeks for geeks se backtracking ke questions kar...confidence aane lagega

    • @shubhamrana412
      @shubhamrana412 4 года назад +3

      Bro aditya bhaiya ki recursion playlist dekhlo fhir aapko for loop bekar lagne lag jayega

    • @deeproy7292
      @deeproy7292 4 года назад +1

      @@shubhamrana412 feeling same bhai

    • @sonulohani
      @sonulohani 3 года назад +1

      @@shubhamrana412 Lekin using for loop is better than using recursion.

    • @vikku_19
      @vikku_19 3 года назад

      @@sonulohani using a loop can be efficient? Btw what is the time complexity of the recursive function does it depend on the recurrence relation?

  • @harshit4190
    @harshit4190 4 года назад +1

    We don't watch videos here in channel, We watch playlists..Amazing content...

  • @akashgkrishnan9596
    @akashgkrishnan9596 3 года назад +4

    Recursion seekhlo DP Halwa lagegi
    .
    .
    .
    edit: ye kon bc dislike kar ra he

  • @pratikjain3323
    @pratikjain3323 3 года назад

    Finally, after 36 minutes, my anxiety of changing n,w -> I, j ended. Through out the video while you were writing the code for iterative I was like "Bhai i,j hoga .. n,w nahi !!! ". Although, I trusted you enough to watch the complete video and then you said.. "Saare n, w ko i, j me badal denge"... Anxiety Ended!

  • @varungoel6981
    @varungoel6981 3 года назад +1

    Today I got selected in Flipkart all because of your videos Aditya!
    Besides learning technical stuff, I got to learn from you on how to handle and approach complex problems.
    Thanks a lot!
    I really owe you a lot, can't msg on LinkedIn since you haven't accepted my request but I'm gonna ping you as soon as I join to thank you :)

  • @akhilk5121
    @akhilk5121 4 года назад

    I have nothing different to say!Commenting just so the dumb youtube algorithm can see this gem and start suggesting. I was trying to learn knapsack and accidently found your playlist comment at the corner of famous video where people were struggling to understand the concept. I was skeptical and almost skipped seeing the video is in Hindi since my hindi is not so great. Somehow i watched the first one and now i am in love with this. You are such an awesome teacher , please keep doing this. Much Love.

  • @noobichesser9434
    @noobichesser9434 3 года назад

    Engrave this in stones and history will witness that best ever tutorials created for Dynamic Programming on entire planet was created by Aditya Verma. Period.

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

    The best explanation of dp, Now I again have some confidence.
    I saw tons of video dp but this is the best.

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

    By far the best video on programming foundation for DP on RUclips or any other educational site. You got an unique and excellent way of expressing complex concepts with simplicity. I hope you will create more videos.

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

    He is teaching like he really cares for us... That line "bas tum recursive function acche se likh do mere bhai 🤍 20:40"

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

    ur explanation is so well that even before seeing this video .. and understanding how DP works , i have solved 20 DP leetcode problems nd i am continuing series now .!

  • @AuritraDey
    @AuritraDey 10 месяцев назад +1

    An elder brother holding the hand of his younger brother and introducing the world of Dynamic Programming. ❤

  • @praveenchouhan6388
    @praveenchouhan6388 3 года назад

    The beauty of your explaination is it gave me a feel as I myself have solved and analyzed the approach and solution of the problem. This is one of the best youtube videos i have ever watched!!!!!!!!!!!!!!!!!thanks keep uploading.............

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

    do doubt one of the best teacher i am confuse in between how to convert recursive code to tabulation and you made it very simple
    thank you dp King.....

  • @prashant5624
    @prashant5624 3 года назад +1

    Thnku so much bhai🙏🙏. U have made dynamic programming as the easiest topic for us. Ur teaching style is amazing 👍👍👍👍

  • @AdityaSingh-ql9ke
    @AdityaSingh-ql9ke 2 года назад +1

    Bhai khatarnaak, kya insight di hai..Thank god for utube and thankgod for u.

  • @ShivamSingh-vh1xz
    @ShivamSingh-vh1xz 4 года назад +1

    Your videos are very helpful .
    Your promise is true that no one on RUclips teach us like you .
    Thanks a lot sir .make more videos on data structure and algorithms it will be helpful for students .♥️♥️

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

    This explanation is tremendous . I wish I had found this earlier!!!.Please post more and more videos!!!!

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

    Hey, very good and in-depth explanation. You seriously took 4 long videos to come to 0/1 knapsack tabulation solution. And to my surprise, they were very much helpful in understanding the concepts. It increases my base interest in dynamic programming. I must say that. Now I understand what lookup table means(used everywhere) that I previously used to confuse a lot in memoization. Thanks a lot!!!
    Just one suggestion, you please mention in the Introduction and in the Title of this video that it is bottom up approach(Tabulation) not top-down DP. No need to make another video or edit any videos. :D

  • @shivsharma387
    @shivsharma387 3 года назад

    What the hell!! This is damn. I prepared for gate and just memorized the approach for different DP problem but from your explanation, I am to understand it thoroughly.. Bhai OP