subset sum problem dynamic programming | backtracking sum of subsets

แชร์
ฝัง
  • เผยแพร่เมื่อ 5 ก.ย. 2024
  • This is a video lecture which explains subset sum problem solving using both backtracking and dynamic programming methods. This explanation is a little long but once you watch it, you won't ever regret about having watched such a long video. Backtracking takes exponential time to solve the subset sum problem therefore, we solve using it dynamic programming. I am sure you will love the explanation :)
    CODE LINK: drive.google.c...
    If you find any difficulty or have any query then do COMMENT below. PLEASE help our channel by SUBSCRIBING and LIKE our video if you found it helpful...CYA :)

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

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

    explained clearly , leaves no doubt in my mind , thank you sir.

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

    the best of the explaination i had seen so far

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

    At first I want to thank you.
    I was trying to understand how the matrix is fullfilling the XOR logic. When I was trying to dry run the code I found, it was not being match with the logic. I have searched and seen a lot of subset sum problem video, even repeat the knapsack video also. Then suddenly at this time of night I find a channel with less subs and even lesser view. I started with very less expectation but sir forgive me for my previous thoughts. I finally understood what is happening and I found by myself that I have a error in my code. When I am able to find the error, I understood the logic. I feel relaxed.
    I will share this channel, and will watch more dp video if u have.

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

    I really love this video. It explain the problem and gives two solutions. With the first solution it builds the required intuition to understand that the problem show a dynamic programming pattern and use it to build up a bottom-up solution. Thank you very much

  • @VS-cy8oy
    @VS-cy8oy 4 ปีที่แล้ว +2

    Thank you very much for this explanation, i went over many videos over youtube but didn't get any intuition for this problem, but the way you distinguished both approaches made me understand this problem very well.

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

    If anyone wants to know how backtracking actually works this is the recommended video. Bro the way you did backtrack till last possibility is amazing. Thank you so much 🙏🏻🥰

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

      Welcome :)

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

      Same feel. I understood backtracking properly with this video. I didn't know that I was doing backtracking when I was coding that method in the first place 😆

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

    most underated channel

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

    bro your explanation is the best! Other videos on youtube don't explain how the table is forming and the sub problems but you explain that.Thanks a lot!

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

      Welcome :)

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

      @@techdose4u bro can you make a video on subset sum divisible by m problem? It's a variant of this problem but harder and i can't understand the approach

  • @AkashKumar-ym4gu
    @AkashKumar-ym4gu 3 ปีที่แล้ว +2

    This Channel Needs To Be Popular..
    Absolutely Great Stuff..
    ❤❤

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

    Hi sir, you teach everything very cleanly...please keep teaching us😊

  • @ShivamSingh-me1nb
    @ShivamSingh-me1nb 4 ปีที่แล้ว +1

    Great explanation, i have never seen anyone explain that much in you tube

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

    Thanks alot Algo Buddy. Words are not enough to praise you but you are the best teacher, its like a magic that you teach even hardest of hard concept as if it was always easy. You are going to rock algo learning world someday for sure.

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

      Thanks for your motivation bro :)

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

    Gave an applaud to this video and another video of yours. Keep up the good work :)

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

      Thanks for supporting us ❤️

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

    I love this channel, thanks for it, i see i have ameliorated a lot, i will always support it

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

    The best explanation!. Made this problem seem so easy . Thanks a lot !

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

    Superb and clear Explanation..You are very great at making these videos for free...

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

    Amazing content. Clearly visible that you are putting a lot of hard work.

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

    IF YOU START AN ONLINE COURSE I LL BE THE FIRST ONE TO REGISTER

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

    Thanks a lot for this.❤️. I finally understood it 😭❤️ . Keep up the good work. :')

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

      Welcome 😊

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

      Rona kya isme🙄😂😂

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

      @@ritiksolanki6267 khushi k aansu

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

    God bless you!
    I was looking for this type of explanation. Please start some online course on which you will cover these topics in-depth.

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

      Yep. I will do it at some point of time.

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

    one day sir you will become the biggest competitor for many other ppl teaching DSA sir. thanks a lot sir ..... : )

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

    Thanks a lot sir. Now I clearly understood.

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

    thanks a lot, i understood the concept behind filling this table ,one syggestion it could b better explained using recurssion tree that includes sub problems.

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

    One of the best explanations of subset sum problem!

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

    Hi Tech Dose, the only request I am putting here is, Can you elaborate how the recursive formula came in every dynamic programming videos?
    Because after seeing your recursive formula only I am able to understand the logic, If you do consider that also, it would be more helpful. Thanks in advance. And one more, the explanation was awesome!!!

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

      Thanks. I will try to derive the recursive formula from now on.

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

      Thank you brother

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

      👍

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

      This is a good requirement. I have first listened to the explanation, proceeded to write Recursive code first, and then wrote the DP. But in essence from interview point of view, it is better to be able to work with bottom up tabulation approach on the fly rather than going through recursion. Here the detailed explanation for filling the table, makes it intuitive enough to stand on its own.

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

    Next level Explanation ✨

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

    Literally you are gem Thanks for your quality teaching keep it up

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

    Very nice explanation in "Abob" (above) Video !

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

    Nice explaination but
    how can you implement tabulation solution directly from the recursive solution
    best way to learn dp is -> 1. find recursive solution, 2. implement memoized version of DP solution from recursive, 3. then at last we can move to tabulation approach

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

    Very well explained! You definitely need more likes..

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

      Thanks for liking ❤️

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

    This is some nice stuff explained superbly!

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

    Amazing explanation bro, can't go without liking.

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

    Very well explained 👍 thank you sir..keep making such videos

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

    clean and crisp
    please make a video on time complexity ?how to find it
    ur explanations are great

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

    I was looking for such videos. Really helpful 👌👍

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

    really best lecture perfect!!..

  • @Mandeepsingh-jo5cf
    @Mandeepsingh-jo5cf 3 ปีที่แล้ว +1

    Thanks for this magical explanation.

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

    @TECH DOSE - Nice video , well explained and I cleared doubt on how to track down the nodes but can you please tell me if I want to see what all subset elements are added to get the sum then how to track back from last node that is 3*5 = T

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

    Great video! :) Liked and subscribed!

  • @user-gg9lr8jz6l
    @user-gg9lr8jz6l หลายเดือนก่อน

    give this man an oscar :)

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

    At first I thought why this is needed because I can iterate all elements in a nested for loop to find the sum. Then I changed {2, 2, 3} and sum {7} instead of 5, by running the attached code. Then it made lot of sense. Instead of needing to iterate with 3 iterator variables over all elements, this method shows a simple technique to get the subset. Now I am convinced. Thanks a lot. Are you converting a n dimensional problem to a 2 dimentional problem with Knapsack?

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

    Very good and clear explanation! Thank you!

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

    Very well explained

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

    Would have been great if you explained memoization method before DP method. Good content btw! Thanks!

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

    Appreciate such a clean explanation

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

    Really good video. I want to point out something @tech_dose that in your code the order of initializing the array with true and false should be swapped(the first row and first column) since if we initialize the column first it will get overwritten.

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

    understanding recursive intuition is easy, and writing that into dp was tough for me. but now if i can come up with recursive soln, i can easily write that into dp. Thanks to @Tech Dose

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

    Great explanation sir!!
    Please also create a video on Sudoku solver🙏

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

    great explanation...
    Thank you, sir.

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

    Great video! The space complexity for dp is O(sum*size(set)) for your method which is bottom-up. But I guess we can perform dp top bottom approach, the Space complexity can be reduced to O(sum+1). Is that correct?

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

      You can just maintain a row to do that

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

    Well illustrated. Thanks

  • @i.vigneshdavid1698
    @i.vigneshdavid1698 4 ปีที่แล้ว +2

    can you tell me how to print elements of subset

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

    Great job, explaining this! 🎉

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

    crystal clear sir, 🙌🙌👏

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

    Bro i can't tell i was finding this from last 2 days...... you are an angel 🔥
    Please tell me can we initialise the 1st row and column within the nested for loop in which we are checking all conditions

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

      I have done in the same way. I am very lazy. So decided not to go for seperate initialization, but just kept if(i==0) d[i][j]=false else if (j==0) d[i][j]=true. I think the only disadvantage of doing it is that each single time when the decision needs to be taken, we will check for i==0 and j==0 for all elements, which can be avoided if we initialize them separately. I think this is the reason maybe to initialize it separately first.

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

    Very nicely explained!

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

    03:05 In the second condition, we are taking the value of 3 and computing 5-3 = 2, but why its sum - set[n-1] when set[n] is the current element.

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

      Here N is length of an array, we need to acess last element of an array, so n-1 will give acess to the last element

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

    crystal clear explanation...

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

    Thanks for the clear explanation. Please make some videos on bitmasking. There are very few available in youtube about bitmasking. Could you please let me know whether this problem can be solved using bit masking?

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

      I will let you know once i try.

    • @bmuralikrishna8054
      @bmuralikrishna8054 5 ปีที่แล้ว

      @@techdose4u thank you for the reply. with the dynamic programming approach, Can we find the total no of subsets that will form the given sum?

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

    you can also say that 0 is present in every subset so thats why thats column is true

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

    Is it necessary for array to be sorted?

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

      Actually you don't need a sorted array. The elements can be in any order, it will start taking elements from 1st postion in the 1st row till last position element in last row.

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

      Moreover, if you can notice, set is an unordered collection of elements. So we should not be concerned about the order but only the elements.

    • @akshaykamathb2788
      @akshaykamathb2788 5 ปีที่แล้ว

      i think YES , you should start with smallest element first to reach the solution

    • @bmuralikrishna8054
      @bmuralikrishna8054 5 ปีที่แล้ว

      I think, For backtracking array no need to be sorted because we are checking for each and every possibility.

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

      @@bmuralikrishna8054 For both the solutions the aray need not to be sorted. Here in example he has just taken the sorted array

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

    super super super amazing thx!!

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

    Can you please explain why we are considering 1 row above? that logic I am not clear with

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

      I will show this in one DP problem soon.

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

    I still cannot understand when do we need to have dp[n+1][target+1]? how have decided the range?

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

      We don't use 0th row and column. So we take 1 extra size

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

    Great ☺️ Thanks for the video

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

    At 2:51, is it required to search the 2nd option if the 1st returns true?
    Also, I wanted to thank you so much for the content. Solving this by hand and following along, helped me understand this concept.

  • @BaljeetSingh-bx8yj
    @BaljeetSingh-bx8yj 3 ปีที่แล้ว +1

    Great explanation!!

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

    but what if i want to find all the subsets from a set, which gives a sum equal to a given value? (using DP, as it just tells me if its possible to get a subset or not i.e. true or false)

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

      You would need to iterate this table to find all the "T" cells and print arr[i-1] of those cells.

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

    Hi there, this is your code describing how to determine if True or False for each cell in matrix
    subset[i][j] = subset[ i - 1][ j ] | |
    subset[i - 1][j - set[i - 1]];
    The second half after the OR operator represents what happens when we SELECT the I'th Element.
    My question is why is it j - set[i - 1] and NOT j - set[ i ].
    Shouldn't we minus the current sum(j) by the current 'weight' (set[i]) of the i'the element and see if the first i - 1 elements can sum up to it?

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

      Same thoughts! I think he made mistakes.

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

      The reason for that is because first the table size is num of elements+1 and subsetsum+1. The first element and the sum are going to be zeroth element and zeroth subsetsum. Hence, whenever we consider the formula, we need to go with -1.

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

      You can run the code and you will be able to see that it works in this manner.

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

      //My Code
      public static boolean isSubSetSumTabulation(int arr[],int subSetsum){
      int n=arr.length;
      boolean dp[][]=new boolean[n+1][subSetsum+1];
      for(int i=0;i

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

    Great video, thank you!

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

    thankkkkuuuu so much sir

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

    Can we find max size of subarray having a sum k say 5 by this technique

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

    Good explained

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

    Understand the significance, backtracking(bt) vs dp
    n : 10 sum : 100070 dp/bt ratio : 977.24609
    n : 20 sum : 3200140 dp/bt ratio : 61.03783
    n : 30 sum : 24300210 dp/bt ratio : 0.67894
    n : 40 sum : 102400280 dp/bt ratio : 0.00373
    n : 50 sum : 312500350 dp/bt ratio : 0.00001
    n : 60 sum : 777600420 dp/bt ratio : 0.00000
    n : 70 sum : 1680700490 dp/bt ratio : 0.00000
    n : 80 sum : 3276800560 dp/bt ratio : 0.00000
    n : 90 sum : 5904900630 dp/bt ratio : 0.00000
    n : 100 sum : 10000000700 dp/bt ratio : 0.00000
    Note : dp/ bt = (n*sum) / (2**n), n=no of elements

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

      awesome! Thank you for the work!

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

    wow thats great job

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

    This solution also possible with O(n) space.

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

      Yes correct. You can do with just storing a row.

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

    How will the solution change, is the set is allowed to have negative numbers..

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

    If number of elements are high and the value are also high, (arr= [23423343, 33427262,62829927] ] ) do we have any other approach apart from exponential complexity?

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

      Recursion is exponential in No of elements and DP is exponential in Target SUM. If one is very large as compared to the other then you can apply the alternate methods.But, if both are large, maybe you can get idea from here: stackoverflow.com/questions/18432759/subset-sum-for-large-sums

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

    Sir any way to print the subsets using dynamic programming?..

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

    thanks 🙂

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

    Thank you so much

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

    same as knapsack problem instead of or u can use 0,1 and maximize

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

    How can I print the Subest using dynamic programming?

  • @yousofgholami5483
    @yousofgholami5483 27 วันที่ผ่านมา

    Awesome

  • @user-qo8bj9en4r
    @user-qo8bj9en4r 2 ปีที่แล้ว +1

    Hi I think you might make a mistake when explaining:
    ISS(set, n, sum) = ISS(set, n - 1, sum) || ISS(set, n-1, sum-set(n - 1)) ;
    shouldn't it be:
    ISS(set, n, sum) = ISS(set, n - 1, sum) || ISS(set, n-1, sum-set(n )) ; ?
    the latter case is when we are including the nth element which means we should substract set[n] from set

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

      If the indexing is same as numbering then it will be same otherwise the other way around. Depends on how we assumed indexing and numbering coz numbering may start from 1 but index always starts at 0. I hope this might help :)

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

      @@techdose4u Aha I see thanks! this makse perfect sense.
      int n = nums.length;
      then
      memo[c] = memo[c] || memo[c - nums[item]];
      or
      int n = nums.length + 1;
      then
      dp[s] = dp[s] || dp[s - nums[item - 1]];

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

      @@user-qo8bj9en4r This is correct. Initalization is what's doing this.

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

    i could understand the dp but recursion i understood

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

    sir did u make video on how to find all the possible subset of sum ? if u made then please comment that video link,Thank you

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

      No I didn't. I think you are asking about bruteforce technique right?

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

    Just wanted to ask is this series enough for placement preparation of dp questions?

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

      Follow my DP playlist Newbie to Expert. If you do that then you have covered the required placement topics. Now just need to keep on practice while doing other problems.

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

    I think the reason why we hop to [j-nums[i-1] th column and [i-1]th row needs to be explained in a better way. It should clearly say that that we are trying to simulate the recursive call stack of the inclusion of the first element, where we call subsetSum(nums, index - 1, sum - nums[index]). This recursion call HITS a base case of sum = 0 with no other element left in the array to choose from. Hence the row 0 and it gives the same result as our recursion base case.
    It's not very intuitive as per the current explanation. You have to go back to the recursion to drive home the point.

  • @vikaspatel-fi8dl
    @vikaspatel-fi8dl ปีที่แล้ว

    how to find which element is added to make SUM??

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

    How to display the subsets that sum to the given value?

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

    🔥🔥🔥🔥🔥🔥🔥🔥🔥

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

    what are the changes made in the code from naive approach I did not get you..
    and Sir please explain how to print in backtracking approach I am unable to get it.

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

    THANK YOU!!

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

    great video!

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

    Bhaiya if the sum is very large , say like 10^8 or 9 then how can we solve it ???? 🤔🤔🤔🤔🤔

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

    You're a BOSSSS!

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

    In the DP approach, how would we print the subset as well if we wanted to?

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

      Simple. Whenever the cell is true, you will just need to print arr[i-1].

  • @HariKrishnan-ff4hf
    @HariKrishnan-ff4hf 4 ปีที่แล้ว +2

    sir,By the way how to print those subsets in backtracking..kindly help sir

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

      In backtracking method, as soon as as you get your SUM = 0 then keep a return flag , make it true and when you return back to parent node then you will get your flag set and so you will understand that current node lies in the path of finding the subset. So whatever choice you made (you chose or you left the current node), you will stick to it. If you had not included the current node to find sum, then final set will exclude that element. This is the process for backtracking method.

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

    Can u plz say which app is using for white board sir