Ep7 - Find all the possible subsets of an array | Power set | Recursion | DSA series

Sdílet
Vložit
  • čas přidán 5. 09. 2024
  • Let us find all the possible subsets of an array. This is a very important question because it will help us a lot when we will solve future questions. So don't miss out this lecture and watch it till the end.
    Practice - bit.ly/39MNFwz
    Code available in Cpp, Java, Python - github.com/Lea...
    Main channel link - bit.ly/3GBAV7f
    DSA Placement series - • DSA Placement series
    Recursion playlist - • Recursion
    🔴Watch the complete Linked List Series • Linked List Series
    To get all updates follow on Instagram
    / frazmohammad
    👨‍💻Utilize free courses, DSA sheet, and articles on Lead Coding website at
    Join our telegram channel for all the important announcements
    t.me/leadcoding
    ✨ Hashtags ✨
    #DSA #Recursion #Placement #Fraz

Komentáře • 209

  • @LearnYardYT
    @LearnYardYT  Před 2 lety +12

    Okay I noticed people want vector lecture right czcams.com/video/SGyutdso6_c/video.html

    • @ajourneyforfun1979
      @ajourneyforfun1979 Před 2 lety

      Thank you 😊, wanted this one

    • @vinaykamble162
      @vinaykamble162 Před 2 lety +1

      Yes....❤️ Baki sab thik hai 🔥

    • @avnishyadav3093
      @avnishyadav3093 Před 2 lety

      yes we want

    • @singla__sisters2928
      @singla__sisters2928 Před 2 lety

      Hlo everyone , 7.1 Java solution is also not working. Can anyone please add the base condition in that as well..

    • @harshsrivastava3047
      @harshsrivastava3047 Před 2 lety

      @@singla__sisters2928 if(i >= v.size()){
      ArrayList tP = new ArrayList();
      ArrayList tT = new ArrayList();
      tT.add(tP);
      return tT;
      }
      check this out,I think this might work.

  • @yeswanthh5068
    @yeswanthh5068 Před 2 lety +13

    A small suggestion, while u are solving a question in one Lang many people might not know that language ,so if u divide the screen and show us all language codes it will be much more effective for everyone.like u need not explain all Lang codes just keep them on the divided screen.you can explain just one while we look at that code which we are comfortable. Hope u understand Thankyou:)

  • @ashharahmed8684
    @ashharahmed8684 Před 2 lety +7

    Thank you Fraz bhai for all the hardwork you're doing for us so that we can crack our placements. The content level is awesome. Learning a lot of thing. Was having exams but I'll be regular now to have the most out of this program. One again thank you bhaijaan 💓

  • @nithins3895
    @nithins3895 Před 2 lety +22

    Understood, but still its difficult for me to understand through c++ as I prefer java always...
    Still managed to understood the concept
    7th day ✌️
    Consistency ✌️✌️
    Bro, can you please share the complete syallabus that you going to cover in these series

    • @nikeshsingh2081
      @nikeshsingh2081 Před 2 lety

      @Codewith_AyushLuthra java ka code link kaha hai

    • @habilehusain
      @habilehusain Před 2 lety

      @Codewith_AyushLuthra code hai but base condition missing hai? did it work for you?

    • @simranarora2817
      @simranarora2817 Před 2 lety

      Hey, is it possible for you to share your java code, it's tough for me understand in cpp

  • @shagunchoudhary3029
    @shagunchoudhary3029 Před 2 lety +2

    Finally I got the solution in easy way..ThankYou! This DSAseries is going to very helpful for students in future also!
    WAITING FOR NEXT VIDEO

  • @bharathkumargadi352
    @bharathkumargadi352 Před 2 lety +2

    Literally you are just amazing . Intuitive way of teaching

  • @krishnendusukumar2233
    @krishnendusukumar2233 Před 2 lety +1

    apne kitna simple bana diya
    Call function and do it for short part
    Trust recursion
    identify base case.
    Thank you bhaiya 🌟

  • @darshanpagar1894
    @darshanpagar1894 Před rokem +1

    In order to get subsets in reverse order just take our last element and pass rest of the array to recursive function.
    if(i < 0) return {{}};
    helper(v, v.size() - 1);
    just do this changes .

  • @vinaykamble162
    @vinaykamble162 Před 2 lety +1

    Firstly I am not understand this approach but when you Explain the recursion tree it will be very very easy to understand the whole concept ❤️ enjoying all video with more motivation 🥰

  • @mohitroshan3856
    @mohitroshan3856 Před 2 lety +1

    Now i got this one, i have watched many videos got it clear from here only. Thanks sir🙏❣️❣️

  • @Raj-pi1pl
    @Raj-pi1pl Před 2 lety +3

    Much awaited video and now the fun begins as the level of questions increase please bring more and more questions like this Bhaiya

  • @singla__sisters2928
    @singla__sisters2928 Před 2 lety +1

    Wonderful! , the way you have explained the first approach is just wow.. going great 💥✌️✌️✌️

  • @productivewind
    @productivewind Před 2 lety

    I have fear of string Data structures but I watched your videos and got it that this is too easy.
    Ep 7 is completed. Sorry for the late comment.
    Your motivation is amazing. 🌟🌟

  • @curiouspatel
    @curiouspatel Před 2 lety

    Ep7 also done successfully ✅
    Bhaiya mza aa ra sbkuchh aap itne achhe se explain krte hai ki koi doubt hi ni rah jata😁

  • @priyankachoudhary934
    @priyankachoudhary934 Před 2 lety

    I like how you edited the thumbnail with the recursion effect. Creative.

  • @gouravmehra007
    @gouravmehra007 Před 2 lety

    very well explained bro. i tried solving this subset problem, i couldn't find a way out, but with the recursion, now i have answer to this type pf problems. thank you

  • @it_08amanagarwal35
    @it_08amanagarwal35 Před 2 lety +1

    Bro Good explanation especially the first approach is new one which I have not seen before but quite good intuition behind subset finding ❤❤❤❤

  • @pritishpattnaik4674
    @pritishpattnaik4674 Před 2 lety

    I liked the first approach , Very nice explanation Fraz bhai , Badhiya laga, confidence bhi aa raha hai

  • @avadhutlohar5181
    @avadhutlohar5181 Před 2 lety +2

    #Day_7
    Little bit tricky but able to understand
    #CONSISTENCY_OP 🔥🔥🔥

  • @ratnasanjay
    @ratnasanjay Před 2 lety +1

    Thankyou bhaiya for sharing your knowledge for free

  • @shifashamasti6727
    @shifashamasti6727 Před 2 lety +2

    At the end of the video, please explain the codes uploaded in python too.
    I'm comfortable with that, but sometimes it gets confusing in the steps when understanding on my own.
    Maybe the line-by-line explanation would help clarify it too.
    I hope you will solve my problem
    thank you

  • @sonalibiswal6337
    @sonalibiswal6337 Před 5 měsíci

    Another thing that we can do is we can sort partial ans in the second for loop, just add sort(x.begin(),x.end()); The time complexity will get a little messed up though but yes, it works here. I tried it out.

  • @anirudrabrahma_0971
    @anirudrabrahma_0971 Před 2 lety +1

    Big bro again you have showed ur regularity ❤️❤️. Your lecture series is going to be very interesting day by day because gradually you are increasing difficulty levels which is really helpful and easy to progress. U r uploading these videos regularly so no need to remind you like everyday I did 😂. #justawesome ur lecture...learnt two detailed approach which is even within a perfect time length...keep doing great, I am also doing from my end. Love you

    • @LearnYardYT
      @LearnYardYT  Před 2 lety

      Thanks again bro, each day your comment gives me an energy dose.

  • @Anurag_Badwahe
    @Anurag_Badwahe Před 2 lety +1

    Keep going bhaiya ✌✌

  • @itssky09
    @itssky09 Před 2 lety

    Yeh baat😍 ache qs aana start ho gaye

  • @ChandanKumar-ph8dl
    @ChandanKumar-ph8dl Před 2 lety +1

    Suru jabardasti kiyen thae....lekin ab maja aa rha h....

  • @ranitbandyopadhyay
    @ranitbandyopadhyay Před 2 lety

    Instead of the first way, we can use bit manipulation inside the function to return the answer. a very good video on recursion.

  • @nikunjjain5212
    @nikunjjain5212 Před rokem

    Never seen recursion being delivered in such. A easy manner

  • @yashrajput6798
    @yashrajput6798 Před 2 lety +1

    nice lecture...upto the mark explanation !!

  • @sanjeevkumar-pk1ko
    @sanjeevkumar-pk1ko Před 2 lety +1

    Hello Sir!! The code for this problem and the order in which the test cases are demanding the ans is , :
    vector powfun(vector &v,int i){
    if(i

  • @apptrendz
    @apptrendz Před 2 lety +2

    Java people will some issue as we move forward if possible explain java code also
    @Lead Coding

  • @dashundev1586
    @dashundev1586 Před 2 lety +1

    Difficulty level has increased

  • @hikikomori9387
    @hikikomori9387 Před 2 lety

    This one was quite difficult to grasp, but did it anyway. Needed a lot brain storming, Thanks Fraz

  • @shivomgoddemonpanchal5460

    thank u sir im solving problem with u daily and it motivate and helping me lot daily at 6pm im waiting for video and learn daily new things thanks a lot sir

  • @Spider-Man_67
    @Spider-Man_67 Před 2 lety +11

    Faraz bhai can you please show and explain the JAVA code too of the programs you solve in the video, I'm from a JAVA background and feel difficulty in understanding C++, it would be really helpful if you just walk through the codes of JAVA.

    • @Iron_Man019
      @Iron_Man019 Před 2 lety +2

      Java code is in description 👍

  • @klvp_techie
    @klvp_techie Před 2 lety +1

    Question :
    Single Program for all subsets of an array or all unique subsets of an array in python
    Logic :
    for every element in array we have two choices either to consider it or not to consider it
    Code:
    def primeSet(nums,i,subset,ans):
    if i == len(nums):
    ans.append(subset[:])
    return
    #considering ith element
    subset.append(nums[i])
    primeSet(nums,i+1,subset,ans)
    while i+1

  • @tanmaypal2003
    @tanmaypal2003 Před 2 lety

    Lecture was nice and interesting but for myself 1st approach was difficult to understand, I watched video many times but it is difficult for me to understand but the 2nd one was easy when you explain recursion tree I was able to understand 2nd approach.

  • @ajourneyforfun1979
    @ajourneyforfun1979 Před 2 lety +1

    Will be starting this lecture now

  • @sunshine5955
    @sunshine5955 Před 2 lety

    Series going so smoothly and good.thanks @Faraz bhaiya to make this superb series for us

  • @Abhishek-fo3fc
    @Abhishek-fo3fc Před 2 lety +1

    Done Understood❤✅

  • @dineshgangirredi1072
    @dineshgangirredi1072 Před rokem

    nice lecture bro, it is helpful, Thank u.

  • @anujadhotre
    @anujadhotre Před 2 lety

    very well explained

  • @sayanchakraborty165
    @sayanchakraborty165 Před 2 lety

    A really good contents given by Fraz bhaiya thank you so much bhaiya .

  • @jagritibansal3421
    @jagritibansal3421 Před rokem

    very nice explanation

  • @isikamaiti9116
    @isikamaiti9116 Před 2 lety

    Very good video sir,maja ageya.

  • @aakashbhargava1
    @aakashbhargava1 Před 2 lety +1

    Bhaiya I have a suggestion ki either aapne vector padhaya hota or question ko thoda aur detail mei discuss Kiya hota. Because difficulty suddenly increase ho gyi.
    Thank you for this course 🙂!!

  • @ayan84240
    @ayan84240 Před 2 lety +3

    Asalamualikum warhamtullahi wabarkatahu
    Jazak'Allah khair bhai
    For the amazing video
    May Allah reward you in both the world's
    Ameen

  • @arghya_0802
    @arghya_0802 Před 2 lety

    Although my exams are going on, still seeing your videos to get a clear my DSA concepts. Thank you sir for this wonderful series!

    • @LearnYardYT
      @LearnYardYT  Před 2 lety +1

      Keep going bro 🔥.
      You gonna make it

    • @arghya_0802
      @arghya_0802 Před 2 lety

      @@LearnYardYT Thank you so much sir for this motivating comments!! Means a lot☺️

    • @arghya_0802
      @arghya_0802 Před 2 lety

      @@LearnYardYT The difficulty level was little more as compared to other lectures, but concept got cleared!! Thank you sir for such wonderful lectures

  • @saha7pritam
    @saha7pritam Před 2 lety +1

    bhaiya would you please include the vector part after the Recursion topic is over ????
    It's a request because the vector portion in the code is going over the mind, but I understand the algorithm very well.
    Best wishes for upcoming videos

  • @cs_in_10_minutes
    @cs_in_10_minutes Před měsícem

    1st approach can be solved by your first submission attempt, just reverse the array in the pwset function, reverse(v.begin(),v.end()):C++

  • @Adiislive
    @Adiislive Před 2 lety

    this one is simple with bit
    did not understand c++ and this approach

  • @meeshatyagi1779
    @meeshatyagi1779 Před 2 lety +1

    public static void helper(ArrayList arr, int index, ArrayList output) {
    if(index == arr.size()) {
    ans.add(output);
    return;
    }
    //without ith element
    helper(arr, index + 1, new ArrayList(output));
    //With ith element
    output.add(arr.get(index));
    helper(arr, index + 1, new ArrayList(output));
    }

    • @alamkhan6688
      @alamkhan6688 Před rokem

      Thank you soo much I was too much confused about java solution of this program thanks ☺

  • @chandanchoudhary349
    @chandanchoudhary349 Před 2 lety +1

    ha bhaiya approach tho dono bhi right h chaye tho phele i th index ko include krlo phir exclude krdena aur uska vice versa

  • @nihalbarudwale
    @nihalbarudwale Před 2 lety

    Bhaiya, in the first approach of solving this problem, we should get the sequencing correct if we just the sort the vector x:partialAns after inserting i'th element i.e v[i]. in second for loop of helper function.
    After doing that all test cases were satisfied.

  • @divyamjariwal3626
    @divyamjariwal3626 Před 2 lety

    Thank you sir....day 7 check....

  • @ABHISHEKKUMAR-ns6om
    @ABHISHEKKUMAR-ns6om Před 2 lety

    Thanks a lot Fraz sir

  • @Engineer_Rajat
    @Engineer_Rajat Před 2 lety

    Wonderful Bhai🥰

  • @samqureshi9415
    @samqureshi9415 Před 2 lety +2

    First reach +++

  • @leninsingh5264
    @leninsingh5264 Před 2 lety

    In the question it's clearly mentioned that the elements in the subset should be sorted in the ascending order. That's why it gives wrong output

  • @TravelTracksByDebo
    @TravelTracksByDebo Před 2 lety

    thank you bhaiya for this wonderful lecture

  • @isikamaiti7656
    @isikamaiti7656 Před 2 lety

    I salute your consistency .

  • @amandixit8342
    @amandixit8342 Před 2 lety

    bhaiya aj meiin smaj gya mathmatical induction wala funda thoda thoda sa , ab bas practice krni iss intution ki bas

  • @sidhant8971
    @sidhant8971 Před 2 lety

    lecture 7 is understood and done.

  • @recreators7624
    @recreators7624 Před 2 lety +1

    Ep-7 done

  • @tarungupta9780
    @tarungupta9780 Před 2 lety

    fraz bhaiya there is more efficient approach like swap the element in the vector and then use recursion please add this approach also 🙏🙏you doing great job bhaiya 😌😌

  • @karandeepsingh5341
    @karandeepsingh5341 Před 2 lety

    Can you tell sir more briefly this question vector working

  • @emtiazahmed5333
    @emtiazahmed5333 Před 2 lety

    ep7done,,, love u bro🥰 best off luck

  • @ramankr0022
    @ramankr0022 Před rokem

    very helpful

  • @manojgmanojg9600
    @manojgmanojg9600 Před 2 lety

    Sir why we have to use vector

  • @shishirsharma8193
    @shishirsharma8193 Před rokem

    love from Nepal.

  • @piyushsrivastava5581
    @piyushsrivastava5581 Před 2 lety +2

    Starting the lec: here are the key points of this lecture ♥️ All subsets of an array problem:
    We could just build up the subset of different size in an array i.e. subset[]. Here are the steps to generate it:
    Choose one element from input i.e. subset[len] = S[pos]. We can decide to include it in current subset or not.
    Recursively form subset including it i.e. allSubsets(pos+1, len+1, subset)
    Recursively form subset excluding it i.e. allSubsets(pos+1, len, subset)
    Make sure to generate each set once.
    # Function to generate a power set of given set `S`
    def findPowerSet(S, s, n):
    # if we have considered all elements
    if n == 0:
    print(s)
    return
    # consider the n'th element
    s.append(S[n - 1])
    findPowerSet(S, s, n - 1)
    s.pop() # backtrack
    # or don't consider the n'th element
    findPowerSet(S, s, n - 1)

  • @rajankhunt7002
    @rajankhunt7002 Před 2 lety

    Good Video

  • @anuraggulati2167
    @anuraggulati2167 Před 2 lety

    Day 7 Done waiting for next lecture 😀😀😀😍😘

  • @amitranjeetjha1240
    @amitranjeetjha1240 Před 2 lety

    Very helpful fraz bhai

  • @aniketyelsalwar
    @aniketyelsalwar Před 2 lety

    I Figured Out the first Approach Sequencing Problem!
    ask recursion to give power set for starting elements..
    Rather asking them to give later elements.
    IN OTHER WORDS, GO FROM BACK TO FRONT!
    ThankYou !!!✌
    vector helper(vector &v, int i) {

    if (i < 0) return {{}} ;
    // ask helper() to return power set for upto (i-1)th ele
    vector partialAns = helper(v, i - 1) ;
    // do my own task
    vector ans ;
    for (vectorx : partialAns) {
    ans.push_back(x) ;
    }
    for (vector x : partialAns) {
    x.push_back(v[i]) ;
    ans.push_back(x);
    }
    return ans ;
    }
    vector pwset(vectorv){
    vector ans = helper(v, v.size()-1) ;
    return ans ;
    }

  • @devanshgupta9283
    @devanshgupta9283 Před 2 lety

    Very nice explained sir.

  • @ViratSingh-zy6mt
    @ViratSingh-zy6mt Před 2 lety

    Could you please make a video on how to use vector or everything about vector??

  • @abhishekpandey8988
    @abhishekpandey8988 Před 2 lety

    Osm explanation bhaiya

  • @abhishekc3556
    @abhishekc3556 Před 2 lety

    Amazing

  • @amandixit8342
    @amandixit8342 Před 2 lety

    i learned one more thing helper fn mein return type non void ke ky disa hai aur void lene se ky faayde hoge ----> agli baar jab b aao toh khud phir se sochna .(ye khud se hi socha ).

  • @shalimar_mehra
    @shalimar_mehra Před 2 lety

    Present ! Sir Would Highly request to you Please tell us the upcoming video topic ! So we just easily cover that topic ! ✔🙌

  • @BurhanAijaz
    @BurhanAijaz Před 2 lety +1

    Day 7, here we go 🔥🔥

  • @Gauravkumar-kc6xh
    @Gauravkumar-kc6xh Před 2 lety

    Great

  • @vaishnavimore4860
    @vaishnavimore4860 Před 2 lety

    Day 7 completed✨
    Waiting for next lecture ☺️

  • @amandixit8342
    @amandixit8342 Před 2 lety

    i learned a difference b/w mathmatical induction and another method which taught by aditya bhaiya
    , method -1 --->so suppose i'm standing at i =0 and my array was 123 , at i =0 i take a decision for i =0 element including it and mera viswass hai apne bade bhai pe ki ab woh 2 and 3 ke liye kaaam karke le aayega when i'm including a ele (mera bhai----> means recursion fun) another decision is not including and after that i'm giving remaining (2 &3 )work to recursion (bhaiya ab tu karke la mere liye, mein thak gya ) , jab mein element nhi include kr raha.
    ====================================================================================================================================
    ====================================================================================================================================
    code :- void helper (vector nums , vector op , int i , int n , vector &v){
    if (i== n+1){
    v.push_back(op) ; // base case
    return ;
    }
    // yhaan mein i = 0 pe decision le raha---> including a ele(i=0)
    op.push_back(nums[i]);
    helper (nums , op , i+1 , n , v); // i= 0 means 1 ka mene including decision le liya aur bol diya bhaiya se 2 and 3 ka including wala ap leke ana mein toh thak gya .
    //another decision ---> i'm not including i =0 element which is 1
    op.pop_back();
    helper (nums , op , i+1 , n , v); // ab again call kr diya bhaiya ko , bhaiya ab mene dusra decision le liya , ab iska kaam b ap karke lao (bichara bhaiya :p).
    }
    vector subsets(vector &nums ){
    // ab yhaan bas zaroorat ki cheeze intialize ki hai jo helper ko chaiye thi krne ke liye
    }
    ------------------------------------------------------------------------------------------===============================================================================
    method 2 ->>> adtiya bhaiya wala bas difference ye hai ki method1 mein ek hi jagah pe decision le raha op mein hi yes then fun call(yes wale decision saare ab bhaiay leke aayege ) and no decision then fun call (no wale saare bhaiya leke aayege), method2 mein op1 and op2 leta hoon phele previous op ko dono mein copy krta hoon and i'm always take a decision in op1 so mein op1.push_back(nums[i]) and op2 mein humesa no wala decision le rha toh usme kuch b push nh kr raha , and then fun call kr duga ek fn m op1 pass krunga and ek mein op2 . that's it .
    dono similar hi hai bas smjne ka intution alag alag hai . ha pata hai meri english shi nhi hai lekin hope hai bhaiay ke sath improve ho jyngi .

  • @aveermukherjee6419
    @aveermukherjee6419 Před 2 lety

    nice explanation keep up the good work.

  • @divyanshsagar
    @divyanshsagar Před 2 lety

    This one is tricky!

  • @manojgmanojg9600
    @manojgmanojg9600 Před 2 lety

    Sir Can we use like this know sir (vector ans) instead of (vector

  • @maazulhaque7293
    @maazulhaque7293 Před 2 lety +1

    Ep-7 Done

  • @sagarpokhriyal6926
    @sagarpokhriyal6926 Před 2 lety

    Fraz bhaiya this recursion series is insane 💯
    Lecture - 7 Completed ☑
    #Dsabyfaraz ❤
    #recursion💯💯

  • @hiiiiiiii927
    @hiiiiiiii927 Před 2 lety

    Done Day 7
    Please bhaiya give more practice questions and homework questions

  • @saisravani2625
    @saisravani2625 Před 2 lety

    watched till end 👍

  • @shrayanbhattacharya
    @shrayanbhattacharya Před 2 lety +1

    I was very excited about the course ... But I don't know c++ .. up till now I could understand by seeing the Java code.. but now I cannot understand... Please do something fraz bhaiya... Explain the Java solution too😞😞

  • @chiragkarnwal6740
    @chiragkarnwal6740 Před 2 lety

    Thanks sir for such a nice content ❤️❤️

  • @svenkatesh7795
    @svenkatesh7795 Před 2 lety

    In second approach you have called the function without the passing the argument(ans vector) as reference.
    In previous approach you passed as reference. I also saw a lot videos in which people always pass vector as reference. Can you explain why so??

  • @sourav1795
    @sourav1795 Před 2 lety

    sir i guess the time complexity will be O(n*2^n) because each subset can have n length . please reply

  • @dailydose75
    @dailydose75 Před 2 lety

    Watched todays video🖐🖐

  • @therock8815
    @therock8815 Před 2 lety

    bhaiya codin ke sath sath vector ka bhi concept bta do jitna use ho raha to easy hoga understanding me

  • @comic_forever
    @comic_forever Před 2 lety

    Today I am revising this lecture before watching toddya's 10th lecture. Bhaiya what will be the recusrion tree for 1st approach?

  • @de_ansh
    @de_ansh Před 2 lety

    Bhaiya This question is bit dificult for me to understand, i tried watching the video twice but still.
    but yes, bhiaya thank you so much for your efforts.