0/1 Knapsack Problem using Dynamic Programming | DSA-One Course #87

แชร์
ฝัง
  • เผยแพร่เมื่อ 8 ก.ย. 2024

ความคิดเห็น • 157

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

    Visualisation is important in DP Problems.
    it's important to understand the basics before diving into complex problems. Otherwise you might get stuck somewhere. I will strongly recommend you to watch the FULL video. Do not skip parts to fully grasp the concept. I've tried to visualise this problem in 3 different ways. You can use any of these ways to visualise your next DP problem.

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

      Bhaiyaa Android ka course continue rakhna. 😊😍

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

      Bhaiya finally apka video aa gya..,, thanks bhaiya,,.. DP should be the first priority if someone wants to get into a good company and also ek acha project...
      Harr exam mei ek dp ka question mill hi jata hai... Or ek maths pe or ek graph ya kisi or algorithm pe

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

      Bhaiya dsAlgo thoda jaldi jaldi cover kariye if possible.
      And bhaiya video lambi hona doesn't matter app please code bhi kar k samjha diya kro!!!

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

      Bhaiya meri abi placements start ho gyi hai ap please yeh ds algo course jald se jald complete kar do

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

      Ha bhaiya *ds algo* pe interview materials bata dijiye pleaseeeeeee 🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏

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

    Best Video ever on 0/1 Knapsack problem which clear all doubts. Thanks, Man.

  • @AbhishekA-81
    @AbhishekA-81 4 ปีที่แล้ว +25

    Thanks a lot bhaiya . Huge support to this channel , was waiting for this course from the time I subscribed this channel.

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

    Bhaiya please Android development ka course continue rakhna....bohot help hoga humlogo k liye ......love you vaiya♥️♥️♥️

    • @ytg6663
      @ytg6663 3 ปีที่แล้ว

      Kyu sab free chahiye kya ? Thoda pay bhi kro...

    • @JamesBond-bi2cr
      @JamesBond-bi2cr 2 ปีที่แล้ว

      @@ytg6663 TH-cam is paying na , all we want is free quality content

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

      @@JamesBond-bi2cr 🙄

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

    your explanation is truly Amazing ! , I have seen 3-4 videos on dynamic programming for the same problem ( as I have started only with dp concepts )but was not getting proper insights on why (?) we are doing the things.
    But you explanation helped me sail through this.
    Thnx a lot for this useful content.

  • @Abhishekkumar-fi2yl
    @Abhishekkumar-fi2yl 4 ปีที่แล้ว +28

    Please DS+ALGO complete krwa do please 🙏(in java)

  • @Anshika.Agrawal
    @Anshika.Agrawal ปีที่แล้ว +5

    Easy Code I did myself...thanks for the easy explanation Bhaiya!
    Attaching the code for reference:
    public class KnapsackProblem {
    public static void main(String[] args) {
    int capacity = 10;
    int[] w = new int[]{1,3,4,6};
    int[] v = new int[]{20,30,10,50};
    solve(capacity,w,v);
    }
    static void solve(int capacity, int[] w, int[] v){
    int[][] mat = new int[w.length+1][capacity+1];
    for(int i=1;ij){
    mat[i][j] = mat[i-1][j];
    }else {
    mat[i][j] = findMax(mat,v,w,i,j);
    }
    }
    }
    }
    findWeights(mat,w,v,capacity);
    for (int i=0;i< mat.length;i++){
    for(int j=0;j0 && i>0 && j>0){
    if(mat[i][j] == mat[i-1][j]){
    i-=1;
    }else {
    ans.add(v[i-1]);
    capacity = capacity-w[i-1];
    for(int index = 0;index< w.length;index++){
    if(w[index]==capacity){
    i = index+1;
    }
    }
    j=capacity;
    }
    }
    System.out.println("Total item == "+ans);
    }
    static int findMax(int[][] mat,int[] v,int[] w, int i,int j){
    int diffVal = 0;
    int diff = j-w[i-1];
    if(diff

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

    Many tutors just explain the text and are unable to create visualization like you did. Thank you.

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

    bhaiya bhaut bhaut shukriya kl s try kr rahi pr iska dp soln smj nahi arra h ....kuki iske memoization part kiya to usme sari values fill nahi ho rahi h thi to smj na aya ......apne achee s btaya h bdia thank u bhaiya

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

    Just solved this problem after your explanation. Such a well-explained video. RESPECT++;

  • @Ashish-db8fr
    @Ashish-db8fr 4 ปีที่แล้ว +4

    Thanks a lot bhaiya !😃
    Your videos help us understand the concepts very well.

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

    Thanks a lot of bhaiya for making the study so easy I have no word for your praises 🙏🙏🙏

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

    Finally sare jagah se kuchh na kuchh sikha phir aya apke lecture ko,khud hi complete code v likh liya ab to.means mehnat rang layi❤️❤️

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

    Bhaiyya yesterday I had my practical, and external got extremely impressed when I explained him this entire problem using dynamic programming. I want to say a big THANK YOU!! to you..❤

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

    awesome video thankyou for clearing my concepts bhaiya

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

    Best explanation thanks a lot

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

    i think most of people dont face problem in understanding concept. Main problem is regarding coding and that is not convered in this. theoritically its easy to understand but without coding it is incomplete. Coding and explaining parallely will be helpful. Thank You.

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

      Totally disagree! If you have a clear logic you can code easily! The problem almost all students face during coding rounds is that they don't have the theoretical logic clear and hence can't code! I don't see any difficulty if you have a clear concept in mind! As such how difficult would it be to code using simple if else while for etc!

  • @ARVINDYADAV-ec6cq
    @ARVINDYADAV-ec6cq 2 ปีที่แล้ว +1

    excellent sir good job

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

    Aap sabse best pdhate ho...ds + java..wo complete karwa do please..bahut request hai bhaiya

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

    Thank you soo much bhaiya. Because of you I am able to solve dp problemns.

  • @AryanSingh-rizz
    @AryanSingh-rizz 6 หลายเดือนก่อน

    The best video ever made on 01 knapsack hands down best video ever. straight to the point ❤❤❤

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

    Great explanation and great work for community . Thanks a lot !!!

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

    Your explanation is truly amazing ...
    I was struggling in learning dp from 2days but after seeing your video i got crystal clear about the concept !
    Thanks a lot !!❤✨

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

    Bhaiya.. please make full complete lectures on data structures and algorithms.. The way u explain is fantastic..

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

    every tutor just simply explained how to do but you explained why ? + how? to do

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

    Best explanation of dp in the internet ❤️
    Thank you anuj bhai❤️

  • @tripathi5174
    @tripathi5174 4 ปีที่แล้ว

    Best video , way better than that TUSHAR!!!

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

    sab jagha dekh liya kahi samjh nahi aaya kaash pahle hi mil jata ye channel bdiya padate ho aap sir

  • @nishantpruthi1172
    @nishantpruthi1172 3 ปีที่แล้ว

    bhaiya meri g*nd ftgi thii iss dynamic programming topic m pr aapne bhot OP smjha dia. Thanks a lot, Huge respect.❤❤

  • @bhaskarmishra8479
    @bhaskarmishra8479 3 ปีที่แล้ว

    Ohhh...Now I think I finally know DP..thank u bhaiyya...had been struggling since so long

  • @kritipchakrabarti3557
    @kritipchakrabarti3557 3 ปีที่แล้ว

    Bhaiya aapka explanation khatarnaaak haiiii.......Best DP teacher aap ho bhaiya.......

  • @md.saifulislam6528
    @md.saifulislam6528 4 ปีที่แล้ว +1

    Thanks bro

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

    mast bataya hai

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

    Bhaiya kuch aur DP problems explain krdo......please.....aur ye bol dijiye ye Recursive style DP k solutions kahan se milenge agar solve nhi horha toh.

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

    Bhaiya Unbounded Knapsack, MCM ko bhi cover kar dena... BTW Great Video 👍

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

    It's very good explanation 😎👌👌

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

    With a very good example beautifully explained man .. Awesome 👍

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

    @anuj bhaiya ,please java, DS and algo. Wala course pura karwado, bich m rh gya ,bhut hope hai bhai, please please please please please and
    ak full stack developer ke lie complete guide ka video bnao , youtube pe bahut h lekin anuj bhiya ak hi h humare, java ka sab kuch clear hogya apka wo series se so please ak video java full stack pe, complete guide...

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

    great explanation👏

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

    you're awesome sir

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

    thank you so much for this. The visualization is excellent

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

    Bhai ur videos r awesome 😎, please keep bringing more content on dp.🙏

  • @Naveenkumar-oh3ks
    @Naveenkumar-oh3ks 3 ปีที่แล้ว +1

    perfect
    explanation

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

    best explanation

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

    Thank you so much bhai for starting dp too 😊😊😊😊😊😊

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

    Best DP videoes on whole youtube...

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

    Thanks bhaiya for this🙏🙏🙏

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

    Please make a video on burst balloon problem too, if possible. :)

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

    baiya dynamic programming pe aur video lana
    the videos are very good and helpful

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

    Great video

  • @abhinavsingh-zc2hk
    @abhinavsingh-zc2hk 3 ปีที่แล้ว +1

    Beautifully Explained :)

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

    Thank you sir.

  • @RandomPerson-hj8fq
    @RandomPerson-hj8fq 4 ปีที่แล้ว +2

    Bhaiya thanks for this video....But please make videos on hard problems of graph such as snake and ladder etc.

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

      If the concepts are clear in the beginning then you can solve Hard problems with ease. Sure, I'll be making more videos on hard problems too but let's start with easy problems first and make our basic concepts stronger.

  • @vinaymahajan8476
    @vinaymahajan8476 4 ปีที่แล้ว

    Looking awesome 😀😀

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

    liked the explanation.

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

    I had question... is this course in continuation to your earlier course of java?? because I am just about to start coding and i love the way you teach... pls reply :)

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

    Thanks a lot

  • @e-volvo735
    @e-volvo735 4 ปีที่แล้ว +1

    #salute

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

    Thanks

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

    Apki java ka Mai Sabhi Videos dekha hu, project ko kaise bnau, beginner ke liye plz bhaiya
    🙏🙏

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

    Bhaiya what is java.lang.StackOverflowError

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

    Please bhaiya make complete series on all Algorithms and CP.

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

    The Efforts!!!🔥🔥

  • @VishalPatel_imvishal
    @VishalPatel_imvishal 3 ปีที่แล้ว

    Thank you so much for thjs video

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

    thank you sir for explaining table in such simple manner

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

    Amazing explanation!

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

    Bhaiya cmplt algo ki series banaao plzzz from start to end

  • @sanketatmaram
    @sanketatmaram 3 ปีที่แล้ว

    Kadak

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

    Bhaiya, Java language par #Project bta dijiye please,

  • @vaibhavakumar5243
    @vaibhavakumar5243 4 ปีที่แล้ว

    Bhaiya dp ki series bhut achi bn rhi hai please isko bnate rahiyega

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

    Hi, if I visualize this tree like that in coin change problem, will it be the same thing? And if yes, then how do we find time complexity in the case without DP as tree will have 4 branches?

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

    Thanks a lot bhaiya - one quick question please, how 6(3) and other 6(3) is same overlapping problem?
    In first 6(3) -> value is 10 as we took [0, 0, 4] weights
    In second 6(3) -> value is 50 as we took [1, 3, 0] weights
    More over the output of both sub-problem will also be different
    In first 6(3) output will be -> 60 as we will take [0, 0, 4, 6] weights
    In second 6(3) output will be -> 110 as we will take [1, ,3, 0, 6] weights
    Am I wrong here?
    Also, I know some where down the line it has over-lapping sub-problems but I can't really figure that out, exactly where?

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

    Pls make a video on how to install ubuntu for competitive programming

  • @Kuriocity
    @Kuriocity 3 ปีที่แล้ว

    Best dry run !

  • @prathmeshfutane1287
    @prathmeshfutane1287 3 ปีที่แล้ว

    Coolllll

  • @shivamgupta-cq2yk
    @shivamgupta-cq2yk 4 ปีที่แล้ว +1

    Bhaiya android development ki next khab ha rhi hai??

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

    Hi Anuj,
    Could you pls relate tree with this table My friend and I got table visualization but not two important things... 1- > how to do conversion from tree (recursion) to memoization and 2. Not clearly choosing of dimension of array.. I am thinking these two Important things but unfortunately nobody telling these important things or might educators are not taking these parts seriously

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

    As compare to other q bhaiya isme bhaut kam repetation hota h dp or recursion m jyada frk nahi ayega agr isko explore krenge example s

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

    Sir java socket ki series bnao please

  • @mubashircodes
    @mubashircodes 4 ปีที่แล้ว

    as u completed java course on apni kaksha in that way pls continue android playlist also thankyou

  • @dewanshkumar1793
    @dewanshkumar1793 4 ปีที่แล้ว

    Bhaiya please complete DS and ALGORITHM 🙏🏻🙏🏻

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

    It’s better if you write the code with explanation

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

    What about in case of multiple items with same weights

  • @varyamsingh7757
    @varyamsingh7757 4 ปีที่แล้ว

    Bhaiya, I am new to hackerRank and I am able to do easy and medium difficulty level questions. My question is what is the difficulty level of coding round questions of product based companies ? Plz guide me so that I can set a goal....hackerrank has “easy...medium...hard..advance...expert” level questions...

  • @priyanshujain2201
    @priyanshujain2201 4 ปีที่แล้ว

    thanku bhiya asee ds algo pe videos lao

  • @hrithikkale443
    @hrithikkale443 3 ปีที่แล้ว

    make a video on knapsack 2 also

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

    Bhaiya placement insight plz batao

  • @deadpool_0077
    @deadpool_0077 4 ปีที่แล้ว

    Android series ka alga project✨

  • @AvinashKumar-ps4tw
    @AvinashKumar-ps4tw 4 ปีที่แล้ว

    bhaiya can you made more video on dp

  • @rishabhkukreja6910
    @rishabhkukreja6910 4 ปีที่แล้ว

    Bhaiya i understood the ques
    But i had one doubt
    Isme humne 2d matrix liya but 0-N knapsack bhi similar kind of ques but usse hum 1d dp se solve karte h
    Aisa kyu ?

  • @shreyakotak3754
    @shreyakotak3754 4 ปีที่แล้ว

    Bhaiya, make one telegram channel as well.

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

    Sir,

  • @FDEN430
    @FDEN430 4 ปีที่แล้ว

    Bhai please make video on full stack android development 🙏🙏

  • @KrishnaGupta-ng4tv
    @KrishnaGupta-ng4tv 4 ปีที่แล้ว

    Please guide us which books to refer

  • @hrithikkale443
    @hrithikkale443 3 ปีที่แล้ว

    if we are able to pick one item more times.then what will be the changes in the code or logic

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

    Bhaiya dp tabulation wali bhi sike ya recursive se kaam chaljega

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

      Ye wala doubt hamesha hi rhta hai 😅. Recursive kare ya loops se kare. But if you think enough, DP is essentially just saving the previous result in memory. Now this memory can contain this data in any form - Array/Map/Matrix.
      In the end what matters is how you find the subproblems and identify the relation between them. So, You can choose any approach Recursive or Iterative, it's upto you.

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

    Bhaiya, Android development k liye ds and algo important h kya??

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

      Algo ka use nai hai...DS aur oopm ka use hai bohot

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

      @@yoyo516 thx bro

    • @yoyo516
      @yoyo516 4 ปีที่แล้ว

      @@ujjawalkumar9214 ✌️

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

    code---> int knapSack(int W, int wt[], int val[], int n)
    {
    vectordp(n+1 , vector(W+1 , 0));
    for(int i=1 ; i

  • @ayushmondal9281
    @ayushmondal9281 4 ปีที่แล้ว

    bhaiya ek naya java placement course start kro....plz🙏🙏🙏🙏 or suggest something on any paid platform...... plz bhaiya

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

    bhai ya vo apni kaksha me java ka course complete karo na es chennal me