6.2 Sum Of Subsets Problem - Backtracking

Поділитися
Вставка
  • Опубліковано 18 вер 2024

КОМЕНТАРІ • 424

  • @monishpidugu5134
    @monishpidugu5134 3 роки тому +464

    Excellent sir I slept while my professor was teaching during my online classes but tomorrow I'm having my exam and I am watching your video's it was very helpful

    • @worldvieweye
      @worldvieweye 2 роки тому +3

      👍🏻👍🏻

    • @srujangurram
      @srujangurram 2 роки тому +9

      Same bro, hope you scored good in your exam

    • @monishpidugu5134
      @monishpidugu5134 2 роки тому +17

      @@srujangurram yeah bro I scored 80 percent in my sem end examination

    • @srujangurram
      @srujangurram 2 роки тому +11

      @@monishpidugu5134 that's awesome ! we have exam tomorrow. hope i does well too 🤞

    • @ingloriousmedia3096
      @ingloriousmedia3096 2 роки тому +64

      I read I slept with my professor 🤣

  • @ayounghosh9218
    @ayounghosh9218 5 років тому +105

    beautifully explained, amazingly clear videography, easily understandable hand writing, simple examples, clear simple English speech so that everyone can understand, slow paced speech so that anyone can grasp the concept, clear audio and the best part is the calm attitude of explanation, just everything that is needed for a perfect explanation, your channel has it.

  • @manish4275
    @manish4275 6 років тому +420

    Even my professor watches ur videos!
    If she forgets something we say her video is buffering 😂😂

  • @yashspr
    @yashspr 6 років тому +56

    I have never come across a better teacher than you sir. Hats off!

  • @NguyenTuan-ek1pv
    @NguyenTuan-ek1pv 2 роки тому +17

    The best teacher ever on UA-cam.
    +1 vote!

  • @alexisxander817
    @alexisxander817 6 років тому +25

    You are such an amazing teacher; everything you explain is understood by me at once, and I am not even a meritorious student lol...
    thank you

  • @gnanajeyam6259
    @gnanajeyam6259 4 роки тому +10

    The way you are explaining the recursion (DFS) is the unique skill you have. I appreciate your time for making this video's. Hope this will helps many people.

  • @gaurav_jha
    @gaurav_jha Рік тому +9

    Just brilliant, it's a privilege to have a teacher like you.

  • @Deepak-jk1eh
    @Deepak-jk1eh 5 років тому +22

    because of your videos i study only one night before of exam ,you r making every student life very easy by just giving these all videos in free ,so thanks you sir .

  • @michaelekoka3263
    @michaelekoka3263 Рік тому +3

    This is an excellent explanation for the backtracking technique to solve this problem. An important precision about this approach, that is missing from the video and that may trip up or confuse the problem solver is that the *weights must be positive*. Without this precision, the bounding function doesn't make sense, since at the time we exceed the target sum during traversal, a later negative weight could bring it to target. So this backtracking approach works only if the weights are positive.

  • @visakh_vijayakumar_
    @visakh_vijayakumar_ 6 років тому +9

    thanks :) only suggestion is @ 6 : 40 it is 27 + 15 =42 ..

  • @surajkumar-px5lf
    @surajkumar-px5lf Рік тому +5

    I don't go class because I know you will clear my all concept before exam. My teacher also made pdf from your lecture's screenshot. You are truly amazing. Sir

  • @f4lld4ark3
    @f4lld4ark3 6 років тому +21

    Best video professor, much hq quality, very nice kanimambo

  • @XYZ-nz5gm
    @XYZ-nz5gm 2 роки тому +2

    not many people can explain this well even though they understand inside out. You did a really good job!

  • @ShubhamKumar-wq9kw
    @ShubhamKumar-wq9kw 6 років тому +82

    content is good...including pseudocode explaination would be really helpful

    • @damansaroa
      @damansaroa 4 роки тому +3

      +1

    • @subinaypanda9936
      @subinaypanda9936 4 роки тому +7

      Sir have already explained how to solve the problem. Now it's your task of solving the whole problem.

  • @unscripted_india
    @unscripted_india 6 років тому +762

    Hit like if you have exams tomorrow and are watching this for end semester.

    • @Pankajkumar-dy9ef
      @Pankajkumar-dy9ef 6 років тому

      yes

    • @abhinavsharma8395
      @abhinavsharma8395 6 років тому

      yes bro

    • @rishiraj8416
      @rishiraj8416 6 років тому +14

      Hit like i have exam today 😂😂😂😂

    • @carlosgallegos1265
      @carlosgallegos1265 5 років тому +9

      If I watched this as my last resource the day before having an exam, I wouldn't pass anything. It's good to take a first glance, or to break apart a problem and solve it, but not as an academic foundation.
      Step up your game, don't be lazy.

    • @TheRegalstreak
      @TheRegalstreak 5 років тому +4

      @@carlosgallegos1265well it depends on person to person. I'm used to studying on the last minute and UA-cam videos are my last resort if I don't understand anything from books and Abdul Bari has been like a God to me literally. I wasn't much into algos and I'm really interested to get into this more. The teachers we have are too underpaid and are not as qualified as well as don't have their concepts clear some of the times. Having a community online helps us help one another and get info quickly without looking into 100s of pages lol.

  • @Sourcegameryt.1M
    @Sourcegameryt.1M Місяць тому +1

    Tomorrow is my sem exam😂😂 just one video of this sir is enough to top DAA exam.
    THANK YOU SIR❤❤❤

  • @rajmourya35
    @rajmourya35 3 роки тому +4

    the way of teaching is so unique. awesome content sir.

  • @MBindu-kc2nj
    @MBindu-kc2nj 2 роки тому +1

    Very helpful sir thank you.
    Initially I thought your videos are too lengthy but now I realized your way of teaching is the best.

  • @cswalker21
    @cswalker21 4 роки тому +5

    Thanks Abdul! Very clear walkthrough of backtracking! It helped me greatly. LOL at the inconsequential arithmetic mistake at 6:39! ;) just shows you're human!

  • @FaKe-rq7cu
    @FaKe-rq7cu 4 роки тому +30

    Very good explanation. I had a little doubt, at 8:18 shouldn't it be greater than or equal to 'm' instead of greater than 'm' in 2nd bounding function. Eg if arr = [1,2,3] & sum = 6, then after including 1 ( [1,5] ), the 2nd bounding function will not let it go further (even though taking all elements would have generated the sum).

    • @anuragjoshi667
      @anuragjoshi667 4 роки тому +3

      Yeah, It seems so. Should have been ≥ m.

    • @mentisdominus
      @mentisdominus 4 роки тому +6

      The 2nd bounding function is correct. It should be greater than m. You only apply the 2nd bounding function when descending down the right branch. When you descend down the right branch, it means that x[i]=0. In your example, after [1,5] and descending down the right branch x[2]=0 which means that 2 will not be included in the solution. The 2nd bounding function is telling you that you will not have enough values to reach the sum 'm' because the values going down the right branch will not be included in the solution. So for arr[1,2,3] and m=6, after taking 1 but not taking 2, you can't reach the value m=6.

    • @peksn
      @peksn 3 роки тому +1

      No because if the rest of the weights can't add up to the number you are searching for then why continue? If the sum of your current sum plus the rest of the objects are less than that number then you'll never get it, so you stop.

  • @henryzhang2992
    @henryzhang2992 4 роки тому +6

    The time complexity for this is still exponential. Consider the case where all of the elements are 1 and the last element is massive. If the target sum is less than the less element but more than all the other elements combined, no nodes are pruned

    • @SahdevSingh-io3qp
      @SahdevSingh-io3qp 8 місяців тому

      See the second bounding condition, if the considered weight + total remaining weight is less than target sum, then no need to search further

    • @SahdevSingh-io3qp
      @SahdevSingh-io3qp 8 місяців тому

      At first call, your example will be terminated

  • @francomartnlumovich4323
    @francomartnlumovich4323 2 роки тому +2

    Very good video. I want to add an improvement to this backtracking. You can add another bonding function, if w array is sorted ascending so X_(i-1) < X_i < X_(i+1) then you know if adding X_i is already greater than m then you kill the node and it's brothers because X_i+1 > X_i

    • @SahdevSingh-io3qp
      @SahdevSingh-io3qp 8 місяців тому

      But sorting also takes some time O(nlogn) and here you are taking time to reduce time, which is meaningless

  • @-PriyankaReddy-tk5ti
    @-PriyankaReddy-tk5ti 5 років тому +25

    Seriously ... my professor given same example...I think she watches ur vedios 😂😂😂😅

  • @ahdibiaimene3588
    @ahdibiaimene3588 2 роки тому +2

    You deserve all my respect sir , such a great teacher i wish you all the best

  • @exe.m1dn1ght
    @exe.m1dn1ght 4 місяці тому +1

    I love Abdul so much ! The way he explains it , calm and cool !! He is a true Master Warrior of Programming !

  • @M-aggi-e
    @M-aggi-e 6 років тому +5

    By far the best explanation Sir. Thank you very much.

  • @karthikbala578
    @karthikbala578 2 місяці тому +8

    1day before Sem

  • @yashjamsandekar5173
    @yashjamsandekar5173 9 місяців тому

    Thankyou so much sir !!!!!
    The way you explained was way more better than any teacher I've came across.

  • @pursuitofcat
    @pursuitofcat 3 роки тому +6

    For benefit of everyone. Here is the manifestation of the concept in code:
    """
    Identify all the subsets of a given set that will
    add upto a given target
    { 5, 10, 12, 13, 15, 18 }, 30 => [{5, 10, 15}, {5, 12, 13}, {12, 18}]
    """
    from typing import List, Set
    def sumOfSubsets(nums: Set[int], target: int):
    def dfs(weights: Set[int]):
    if sum(weights) == target:
    output.append(list(weights))
    other_weights = nums.difference(weights)
    # choose weights in an increasing order to avoid duplication of
    # results
    if len(weights) > 0:
    other_weights = [w for w in other_weights if w > max(weights)]
    for weight in other_weights:
    if sum(weights) + weight

  • @relaxationmusic3535
    @relaxationmusic3535 2 роки тому +2

    what an explaination just outstanding thanku so much sir

  • @shoaibshaik1507
    @shoaibshaik1507 4 роки тому +2

    Mashallah Sir aap ki class superb...Ur teaching mind-blowing sir 👍

  • @droptimistic7419
    @droptimistic7419 4 роки тому +1

    I was just misunderstanding of something and by seeing this great video all confusions became clear, thank you

  • @mekalasailatha8613
    @mekalasailatha8613 4 роки тому +2

    It may be any tough sum,u make it easier by your explanation 😊

  • @rakshakedlaya8752
    @rakshakedlaya8752 3 роки тому +2

    You explained it very well... This video helped me a lot...Thank you so much sir❤🙏

  • @bk5268
    @bk5268 6 років тому +3

    Tq u sir it is very useful me because tmr my daa exam tq u so much it is one of the my dout how to solve this but now i know how to subsititute

  • @tng3100
    @tng3100 Рік тому

    Just saw this video on morning of my sem exam for 4 min ,dayumm just helped a lot ,didn't expect they would ask this. Guess im so lucky afterall

  • @tanmaygarg7200
    @tanmaygarg7200 2 роки тому +1

    A few questions I had:
    1. Why don't we sort the array?
    2. Does this not work for negative integers?
    3. What is the complexity of this algorithm?
    4. What if we have a list whose sum is 31? Won't that be a worst case scenario as we'll end up iterating through all 2^n possible paths and not find any solution?

  • @adarshshenoy0623
    @adarshshenoy0623 5 років тому +2

    Thank you so much sir for your videos it ws too good and the way your explaining the concepts are not complicated . It helped me a lot thank you once again.

  • @ItsmeBhanu.19
    @ItsmeBhanu.19 3 роки тому +2

    wonderful teaching sir thank u so much

  • @prarabdhjoshi9083
    @prarabdhjoshi9083 6 років тому +3

    sir, I have been looking for a good explanation for this problem using recursion since long. So far I found people directly starting with DP solutions where they create the DP table. That is just like mugging up. It is not intuitive at all. You can think of it after you have thought of a recursive solution. Atleast that's what I do. Thanks a lot for making this video. You made my day!

  • @dheerajashishpreetham6812
    @dheerajashishpreetham6812 3 роки тому +6

    How can the value of m remain 33 when we not including 4th object ie x4=0 i think the ans 27,46. correct me if im wrong

    • @Short_Talk_71
      @Short_Talk_71 Рік тому

      Yes bro u are right. That's why i come to the comment section. I am sure any one student are done comment on this silly mistake.

    • @maxpayne7302
      @maxpayne7302 5 місяців тому

      He does the same at 27,18 idk i think that is how you do it.

    • @numanali8545
      @numanali8545 4 місяці тому

      He is just taking track of remaining weight to become 0, that's why he is decreasing regardless of including or excluding the element

    • @williamhogrider4136
      @williamhogrider4136 3 місяці тому

      The left part of the node is the sum of all the x you included until now but the right part is the sum of all the remaining x you can add, so the right part changes repeatedly no matter if you include the particular x or not. So when x4 is excluded, the remaining choices you have are just x5 and x6, so sum would be x5 + x6 = 15+18 = 33 not 46. So think of the right part as something that has the sum of the remaining elements after a level you're at. At level x2, the values is x3+x4+.... and at x3 it is x4+x5+.... .

  • @BrandonMukum
    @BrandonMukum 6 місяців тому

    This man is a savior.

  • @bgminever7436
    @bgminever7436 3 роки тому

    Sir u will get world's best teaching skills person🙏Award

  • @jimmiejohnsson2272
    @jimmiejohnsson2272 2 роки тому

    Great explanation, good example and very easy to follow. I managed to implement and use this very quickly. Thanks a lot!

  • @bharatishinde7169
    @bharatishinde7169 6 років тому +2

    NICE METHODS AND WAY OF TEACHING

  • @priyankarangarajan9336
    @priyankarangarajan9336 4 роки тому

    You take class awesome sir mainly this subset class sir i learn subset sir👌👌👌

  • @vincentrastello720
    @vincentrastello720 2 роки тому

    Great explanation, much better than my professor

  • @sankeerthreddy9865
    @sankeerthreddy9865 6 років тому +2

    Master of teaching😃

  • @fernandosanchezvillanueva4762
    @fernandosanchezvillanueva4762 4 роки тому +2

    Save me the day!! I will see you on Udemy

  • @miguelduarte4287
    @miguelduarte4287 3 місяці тому

    you re the real king, Abdul Bari

  • @ChillitsmecarlChill
    @ChillitsmecarlChill 4 місяці тому

    Ye toh Abdul baari haii ye toh acha bacha haiii, ye duayein sunta haiii, achi baatein batata haii 💆🧘

  • @UTechHacks
    @UTechHacks 4 роки тому +3

    at 6:35 ,, 27+15 = 42 not 43
    😉

  • @shilpapushparaj9988
    @shilpapushparaj9988 6 років тому +2

    Excellent teaching 😎😎

  • @priyanshigupta1359
    @priyanshigupta1359 3 роки тому +1

    best explanation ever , thanks sir

  • @captainsamar
    @captainsamar 6 років тому +2

    Very well explained Abdul

  • @saket_gaming4071
    @saket_gaming4071 3 роки тому +25

    Sir, could you make coding videos of these algorithms as well? It would really help us:)

  • @anaghaprabhu9293
    @anaghaprabhu9293 6 років тому +2

    I appreciate ur work sir. You are really amazing. .

  • @rajanarasada2081
    @rajanarasada2081 2 роки тому

    Super explanation sir I hope this explanation will make all queries clear

  • @nuriagiselaocampo5467
    @nuriagiselaocampo5467 Рік тому

    Colaboren con este excelentísimo !

  • @arafatahmmed263
    @arafatahmmed263 4 роки тому

    Thn...x for your explanation. Addition or discussion of time and space complexity will make you unique form others.

  • @iam_bunny3239
    @iam_bunny3239 2 роки тому +1

    Very nice explanation sir

  • @aadarshkumayan5960
    @aadarshkumayan5960 6 років тому

    Very informative lecture series for starting with Backtracking

  • @balajisolunke4482
    @balajisolunke4482 10 місяців тому

    THANK YOU SIR , YOUR EXPLAINATION WAS SO EXCELLENT

  • @chandukrishna4809
    @chandukrishna4809 4 роки тому +1

    Thanks for the wonderful videos and It would be really helpful if you include writing code for this kind of DP, Back tracking Problems. May be, by watching your code, most people may get essence of "how to write code" for this kind of problems. My request is to include code for at least one problem of such type as including for all will be hectic.

  • @itsupport8245
    @itsupport8245 6 років тому +34

    Sir, pls give us code with this problem..

  • @marypulapa3743
    @marypulapa3743 6 років тому

    Sir outstanding explanation ... Sir really its easy to understand

  • @tiyasakhan994
    @tiyasakhan994 2 роки тому +1

    he : I am not the messiah
    us: he is the messiah!

  • @vinayaktulsian6276
    @vinayaktulsian6276 6 років тому

    Very nice sir thank you for helping us one day before our exam , you teach very well.

  • @svarajdhanulkar1791
    @svarajdhanulkar1791 4 роки тому +1

    Sir ji dhnayaavad bot thanku apkaa. Iss sem ka Daa aap hi nikalonge mera😊

  • @VipulDhaigude
    @VipulDhaigude 4 роки тому

    Such simple and excellent explaination.

  • @killer0200318
    @killer0200318 3 роки тому +1

    Honestly the best explanation ive found

  • @akashmaurya5338
    @akashmaurya5338 5 років тому +43

    how many of you are watchin 1.5x or 2x hit like here
    kabi kabhi nhi hamesha lagta hai ki sir ich bhagwan hai.... akash gaytunde

  • @ok123ut
    @ok123ut 5 років тому +2

    amazing explanation on this!

  • @anjurawat9274
    @anjurawat9274 5 років тому +1

    nice explanation sir

  • @hitmandevil6935
    @hitmandevil6935 6 років тому

    Sir, the way you explain is actually great (it clears the concepts well). But I have a question, how to implement these solutions in a program, how to code these strategies with an efficient implementation. It would be very kind of you if you attach a link in the description (or make some more videos) stating the codes and what's the idea behind its efficient implementation. Thanks in advance....!!!

  • @footballforyou8856
    @footballforyou8856 6 років тому +2

    Thanks a lot sir.good explanation.

  • @techhackz2897
    @techhackz2897 2 роки тому +1

    python code::
    l1=[5 , 10 , 12 , 13 , 15 , 18]
    tot_sum=0
    for l in l1:
    tot_sum+=l
    weight_sum=0
    m=30
    sol=0
    def backtrack(weights , index , weight_sum , tot_sum):
    global sol,m
    print(weights , index , weight_sum , tot_sum)
    if weight_sum==m:
    print("yess")
    sol+=1
    return
    if weight_sum>m:
    return
    if index>=len(weights):
    return
    backtrack(weights , index+1 , weight_sum+weights[index] , tot_sum-weights[index])
    backtrack(weights , index+1 , weight_sum , tot_sum-weights[index])
    backtrack(l1 , 0 , 0 , tot_sum)
    print(sol)

  • @vinitsunita
    @vinitsunita 5 років тому

    crisp and clear explaination

  • @codelearner3666
    @codelearner3666 6 років тому +1

    thank you so much, sir, your videos are really knowledgeable and helpful.

  • @kennethmensah4480
    @kennethmensah4480 3 роки тому

    This man is a genius

  • @gopikrishna1551
    @gopikrishna1551 3 роки тому +2

    sir what is the time complexity for this problem? do we consider height as timecomplexity?

  • @Manish-xc6is
    @Manish-xc6is 3 роки тому

    Watching these for the third time for my 2nd supplymentary

  • @akashchandra6400
    @akashchandra6400 2 роки тому

    thanks sir i have cleared my backlogs

  • @DhruvPatel-km8kj
    @DhruvPatel-km8kj 6 років тому +2

    Excellent work..

  • @nayab.rasool22
    @nayab.rasool22 8 місяців тому +1

    6:32 the given numbers are in descending order. Whats the point of adding 15 (next element )? Can somebody explain

  • @alfabinomial6183
    @alfabinomial6183 5 років тому

    wow !! so intelligent lecture !! sir

  • @RAGHUNATHSINGHBCI
    @RAGHUNATHSINGHBCI Рік тому

    Thank you sir, I love your explaination😍 just one suggestion keep video time minimum for other video

  • @NIKHIL-nv8wu
    @NIKHIL-nv8wu 5 років тому

    Thank you sir for good video lecture,I can understand easily

  • @abmsamsuzzaman4805
    @abmsamsuzzaman4805 4 роки тому

    To understand the algorithm your videos are awesome. But I would suggest if you could please add the pseudocode at least while explaining the algorithm it would been more helpful.

  • @mandilal94
    @mandilal94 6 років тому

    Excellent Teaching sir.Thank you

  • @Ridewithmelkevar
    @Ridewithmelkevar 3 місяці тому +1

    Even our Daa Sir sent ur videos .don't know why they are getting salary which belongs to you .sir 😢

  • @ripuvendrasingh8497
    @ripuvendrasingh8497 5 років тому +1

    everyone is gangsta untill a real gangsta walk in ..

  • @bhavyamadaan7109
    @bhavyamadaan7109 3 роки тому +1

    At 6.17 when we are excluding 4th node then why we are using sum that come when we include the 4th node?

    • @wisdom5603
      @wisdom5603 2 роки тому

      I do have the same doubt ma'am

    • @PetBuddies
      @PetBuddies 2 роки тому

      I know right!!!

  • @himanshusingh3056
    @himanshusingh3056 6 років тому

    Superb Explanation for this problem !

  • @AmirKhan-sg8jb
    @AmirKhan-sg8jb 5 місяців тому

    professor of professors!!!

  • @kiranmallikarjun8618
    @kiranmallikarjun8618 5 років тому +1

    I have a doubt on that we did not include some items so that y u reduce the total weight from where we did not consider that item

  • @revanthnagabathula5476
    @revanthnagabathula5476 Рік тому

    My exam is today and watching this concept now 😂

  • @vikasarya7515
    @vikasarya7515 3 роки тому +2

    Video cut at 5:34.

  • @yizhang7027
    @yizhang7027 3 роки тому

    State-space tree is such an amazing tool. Why haven't I heard about it earlier?