Ep11- Combinations | Find all possible combinations of k numbers out of the range 1 to N | Recursion

Поделиться
HTML-код
  • Опубликовано: 12 дек 2024

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

  • @manojgollapelli9856
    @manojgollapelli9856 2 года назад +14

    Summarization:
    1. Generate all subsets and add size of k into the ans
    2. discard all the subsets more than size of k
    3. skip the combinations which may not have chance to get of k elements.

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

    Really.........Now I would start enjoying with Recursion from when Fraz bhaiya would start teaching about Recursion!!......Thanks alot bhaiya!!

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

    Thanks for the lectres bhaiya,
    I understood the whole thing,
    Here is the summary for today's lecture..
    1. Think of generating all the subsets of size k,
    2. Think of the base case carefully(it can help us optimize the code)
    3. Use the I&I method(include and ignore )

  • @Sandeep-zd6dq
    @Sandeep-zd6dq 2 года назад

    Although I have never used that smaller condition but it really gives a lot more clarity and one thing also that this pick/non-pick strategy will always used when your answer is of smaller size as compared to input because then only you have the option to not-pick otherwise if it would be the permutations then answer is of same size therefore you can’t use it there.

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

    I think space complexity will also be O2^n as in worst case 2^n recursion calls will be stored in recursion call stack

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

      for recurtion its n and for prepareing the final result 2d array its 2^n

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

    Really enjoyed solving the problem together.

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

    Done Day 11
    start from i=1 and include the number meanwhile decrement k and increment i
    pop the element i and increment the i and if at any point i>n && k==0 add the subset to the ans arraylist and return it

  • @beTheChange12
    @beTheChange12 10 месяцев назад

    amazing explanation bhaiya because of you I am loving recursion

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

    Bhaiya aapke Recursion ka video Dekh ke lagta hai ki,
    Sare Data Structure Chor Ke Kewal Recursion hi Padhu.
    It's amazing videos ❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤

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

    Summary:
    1. This question is a variation of generating all possible subsets
    2. Here we have been given a value k and n and we need to generate all possible subsets starting from i = 1 till i

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

      Love this❣️🥰 thank u i wanna be very thankful for u for making this summary pls make it daily i also try but i cant💔

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

      @@emtiazahmed5333 Thank you so much for replying. Will try to make the summaries of every lecture. It will benefit the entire community of students learning the course

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

      @@arghya_0802 i will wait for your summary comment🥰 i totally new.. Its very beneficial for me❣️ thank u

  • @AkshayKumar-qo2yn
    @AkshayKumar-qo2yn 2 года назад

    Notes:
    Problem is somewhat similar to subset problem, but here we can limit the recursion tree as per the provided value of k. The think to note is extra optimisation that we applied in the end to furthur limit the size of the recursion tree, in order to further remove time complexity.
    Time complexity = O(2^N) (since big O notation represents upper bound hence we can keep this as time complexity, though the actual run time complexity will always be less)
    Space Complexity = O(N) Not considering the size of result array.

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

    In Combination problem we basically consider all subsets of size 2 , after that we start bounding the solution as soon as size of ans become equals to k we add that ans to our result and as the condition we get the required element is greater than the remaining element we return from that point ,these help in reducing the time complexity but worst case time complexity is same as O(2^n)

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

    lecture 11 done 😍😍😍👌👌🤞 waiting for the next episode 🖤🖤🖤🖤

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

    i like your apriciation bhaiya

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

    This series is verry helpfull and i read verry more understanding so i will place in 30 days. ❤‍🔥❤‍🔥❤‍🔥❤‍🔥

  • @saipradeepkatakam9734
    @saipradeepkatakam9734 2 года назад +7

    My Summarization:
    Selecting all the subsets of size k value from n.
    1.Take the element -> k-1 , Skip the element ->k.
    2.Base conditions:
    (i) if we reach k==0, then push subset into ans and return.
    (ii) if k value is greater than remaining elements in n (n-i+1) then return.
    (iii) if current(i) value greater than n we return.

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

      Algo : 3:30
      Code : 10:30
      Optimization : 17:50

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

    Day 11 done ✅✅
    Mast tha 🙂

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

    Episode 11 completed!🔥
    Combination
    Here,the problem is same as the subsets problem but we need to generate the subsets of length k
    1) Instead of pushing our subset inside the ans when i reaches n we can do this priorly but pushing the subset when the length of the subset equals k so by this we can stop the growth of tree this will reduce the run time(Time complexity slightly)
    2)If our required elements is greater than remaining elements ie
    If k>n-i+1 then there is no sense of skipping elements so we need to return
    Eg:-When k is 10 and i is 11 and n is 20

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

    wonderful explanation recursion looking easy

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

    Bro excellent lecture again and the intuition behind the question helps me to get the question done by me without seeing the solution ❤❤❤❤❤❤❤❤❤❤❤❤❤❤

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

    Thankyou bhaiya for this session

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

    1.base case
    2.take the element
    3.backtrack
    4.ignore the element

  • @Abhishek-fo3fc
    @Abhishek-fo3fc 2 года назад +1

    Done Understood❤✅

  • @Abc-lr4bf
    @Abc-lr4bf Год назад

    Very nice explanation , thanks

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

    ''Combinations''
    Prerequisite: Subset problem
    -- This is similar to subset problem which we have done earlier but the difference is just that in subset we wanted all the subsets but in this we just want the subsets of the specified size K.
    -- We have two choices either to consider the element or to skip the ith element, we will return the function once the number of element goes beyond the N.
    --To remove the larger subset we will put a condition i.e. we will return out function once k==0 and adding our subset into the ans.
    -- One more improvement is there to remove the unnecessary process when we have lesser elements remaining than the required K elements. E.g. we have skipped all the elements till 10 and we have N = 20, K = 10 so if we skip the 11th element too we will only have 9 elements left which is less than K = 10, we'll put a condition k > n-i+1 then return. This will improve our runtime.
    Time complexity: O(2^n)
    Space complexity: O(n)

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

    Selecting all the subsets of size k value from n.
    1.Take the element -> k-1 , Skip the element ->k.
    2.Base conditions:
    (i) if we reach k==0, then push subset into ans and return.
    (ii) if k value is greater than remaining elements in n (n-i+1) then return.
    (iii) if current(i) value greater than n we return.

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

    Good Explaination bro,
    i tried and succeed,
    Consistency✌✌ #Day11

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

    Need to watch it again

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

    Day 11
    aaj itna jaldi post 🔥🔥

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

    Thanks Fraz for the entire recursion series.

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

    Thanks for the lectures and all your efforts sir🧡🧡🧡🧡🧡

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

    #EP_11 completed
    Consistency_OP 🔥🔥🔥

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

    Summarize
    first is the genrate all the posible and recuired subset and other is the efficient base case and bounded condition.

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

    Bhaiya ur lectures are awsome but can u plz make a video on "Time & Space complexity" as i am finding it difficult.
    And its a humble request to make the video before 31st May (ie before the Contest), if possible/-

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

    Day 11 Done bhaiya👍

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

    How many lectures for recursion are remaining? Please please tell

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

    summarization :
    if index is greater than n :
    return from it
    if length of subset greater than k return from it
    if required number of elements are greater than remaining number of elements return from it.
    above three are base conditions
    there are two ways to create a subset:
    one way :to choose i th element and ask the recursion to do the remaining task by decresing the k-required number of elements by 1 i.e k-1
    pop the elements in the subset.
    other way : by ignoring the i th element and ask recursion to do the remaining task by keeping the k to be
    unchanged bcoz we didnot consider any element in the subset.

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

    Identify the problem is solved using this algorithm .
    ist is the finding label word and range 1 to n
    and 2nd is the exhitibition k
    and if word is present combination so better understand is type of problem solve using this recursion algorithm.

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

    Kal iss sem ka last exam hai But still I am watching videos 😍

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

    Complete Day 11 ❤️

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

    Good Video

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

    Nice explanation 👌

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

    yes done day 11 🙌❤️

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

    Bhot zbrdst

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

    Nice explain.

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

    summary of combination:
    1. find powerset by using recursion ( include item and then exclude item)
    2if index size greater than size of value array, return
    3if no of combination (k) equal to zero , add sunset of array into result array
    4if no of required combination greater than no of given element,return as it will not fulfill condition anyway
    k>(n-i+1)

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

    Lecture 11 Done ☑
    #dsabyfaraz🌠

  • @aashishgupta9392
    @aashishgupta9392 2 года назад +5

    How many more recursion lectures?

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

      7 may be

  • @codeByteLH
    @codeByteLH 9 месяцев назад

    Summary:
    1.Approach started with either we can take ith ele or skip
    2. For optimisation we have to consider that no of element in subset should not more than value of k
    3. Dry run for Better understanding

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

    Thankyou bhaiya.

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

    Complete and conquer..

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

    In the last base condition where we're avoiding very short subsets, the base condition should be (subset.size()+n-i+1 < k)

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

    Thanks bhaiya

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

    Hello Fraz, have you ever tried submitting the answers in Python or Java uploaded in github ?. I see the answers are not accepted even though everything seems to be right. I understand Platform should not matter but our logic building needs to improve and how we are solving the problem matters. If we see the test cases failing for every problem we do get demotivated and in such scenarios where you organize contests, other than c++ users won't even have a chance to win or even at least submit their answers.
    (Try submitting answer in other languages , in c++ it does not even bother about constraints but in other languages scenario is totally different)

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

      who told u in cpp constraints dont bother people?

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

      @@RajputAnkit11 have you ever tried code studio with fraz c++ code ?. if not please do try. I don't see any constraints in his code. Although logic maters the most but my main concern here is about the platform which is not accepting code in python or java. In Code studio, C++ has better privileges
      Try submitting code other than c++ and you will figure it out.

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

    Thank you so so much Fraz Bhaiya for your every efforts towards us✨❤

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

    Episode 11 done! 🔥🔥

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

    Great video😀

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

    done for day 11😊

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

    thank you

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

    11 Done ✅

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

    Episode -11 Completed

  • @totototo-l8m
    @totototo-l8m 10 месяцев назад

    Nice

  • @Hariharan-uy7ob
    @Hariharan-uy7ob 2 года назад +1

    Make video for vector concept I got error while try to run the code on another compiler

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

    Just a slight modification to the subset problem .This is the code :-
    #include
    void combination(int i,int n,int k,vector &combi,vector &combi_ans,vector &arr)
    {
    if(i==n)
    {
    if(combi.size()==k)
    {
    combi_ans.push_back(combi);
    }
    return;
    }
    else
    {
    combi.push_back(arr[i]);
    combination(i+1,n,k,combi,combi_ans,arr);
    combi.pop_back();
    combination(i+1,n,k,combi,combi_ans,arr);
    }
    }
    vector combinations(int n, int k)
    {
    // Write your code here.
    vector arr;
    for(int i=1;i

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

      @Ayush Chopra What is a base subset?Subsets are meant to change.I think u r talking about the base set which is not changing it is vector &arr. not combi. combi is used to generate subsets so it should change.

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

      @Ayush Chopra It will keep track of every subset by backtracking.

  • @Gauravkumar-kc6xh
    @Gauravkumar-kc6xh 2 года назад

    Great

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

    Present ! ✅🙌

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

    --> Here is my approach where we will not call the function if we dont require we will be calling only if there is a possibility to generate subset of required size.i used an approach which is similar to that of permutations. This code took only 160 ms runtime.
    by the way this playlist is very helpfull in developing the concept of recursion and actually apply it on our own approach thank you bhaiya for this amazing content. :)
    #include
    void solve(vectora,vector&ans,int k,vectors){
    if(a.size()==k){
    ans.push_back(a);
    }
    else{
    int d= a.size()-1;
    if(d

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

    Combinations
    Given : K=2 -->Boundation (So ,Subset with Combination of 2 nos.)
    Idea point : Either selecting i'th element into the subset or Ignoring it
    Base condition :(i) till I reaches the last element
    (ii) if size of subset == k(Constraint/Condition)
    Dont go through it further
    IF TAKE push the i'th element into the subset
    Ask recursion to do the further task from I+1 and also pass k-1 as I have selected one element already once.
    IF SKIP pop that out and ask the recursion to do the similar further task.
    if(k==0)..ie: size of k=2
    Then push it into the ans.
    and
    if (I>N) then return
    Also if ( k>n-i+1 ) then return as we can't further form a subset of desired size.

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

    bhaiya I have thought of a base case where if the subSet size is equal to k then we will save the ans and return ? Is this correct ?

  • @Zeeshan_Ahmad-
    @Zeeshan_Ahmad- 2 года назад

    BSc se hoon big product company ke liye pay after placement program OR MCA from local colleges ?

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

    Bhaiya beginner DSA series kab aayegi pls 🙏 reply krna

  • @mahedihassan3956
    @mahedihassan3956 11 месяцев назад

    Exam in 2 days now i am watching it with 2× speed....😅😅😅

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

    My summarization :
    so here if we take the ith element , the add it to ur data structure and call the helper function recursively for the i+1th element with k-1 as we have toom that element , if we don't pick the ith element then we would backtrack and pop it out from our data structure and and call recursively for i+1th element with k as we have not taken it,
    and if the k reaches 0 then add it to ans vector and if i exceeds n simply return

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

    can you please dry run this whole code, not the recursion tree but every iteration?

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

    Where can I practice questions on recursion...or watching your lectures are enough??

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

    May you explain the python code please?

  • @Lucifer-xt7un
    @Lucifer-xt7un 2 года назад

    Consistency ++

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

    pls tell me how you will find remainingelements = n-i+1 ?

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

    Done✅

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

    Bro...in your journey...on you first go...did u solve generating permutations.. generating subsets kind of problems.?

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

      baas video dekhte jaa thode din baad samaj ayega ye topic kyu choose kiye tha

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

      @@vinodthakar4561 please say in English...I don't know hindi

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

    For the first solution, initially i=1 and k=2, then i=2 and k=1, then i=3 and k=0, now again the recursive call is made, and now i=4 and k=-1, then i=5 and k=-2. Now the if condition says if(i>n) here 5 is greater than 4, so the condition is true. Moving to the next if statement (k==0) but the value of k is -2, so how it is being done now, i am confused from this step.

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

    Syllabus of tomorrow's contest bhaiya?

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

    🔥🔥🔥🔥❣️

  • @AnandKumar-ji6wb
    @AnandKumar-ji6wb 2 года назад

    more video

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

    How is n-i+1 remaining elements?

  • @abhishekdwivedi-ll5ky
    @abhishekdwivedi-ll5ky 2 года назад

    Bhaiya ye jo 3re base condition hai ye to galat lag rhi hai... recursion tree bnane ke baad bhi galat aa rha hai ...
    Plzz guide

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

    Isn’t the complexity k*2^n ?

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

    Sir this is the solution to your homework problem:-
    #include
    void sumcomb(int i,int n,vector &arr,vector &comb,int sum,vector &ans)
    {
    if(sum==0)
    {
    ans.push_back(comb);
    return;
    }
    else if(sum

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

    First

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

    Yaar mai socha tha series ikdam basic se rahegi dsa ki per achanak se recursion mai vector aa gaya phir string aa gaya aab wo shamjna padd raha hai alag se toh thoda demotivate ho gaya hu

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

      Yahi to hustle hai.
      Karo ye sab

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

      ye sb choti chiz se Darna nhi h . Remember one thing "Jab tk todenge nhi tbtk chhodenge nhi"😅😅

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

    These are subsequences, not subsets.

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

    I tried and came up with this code, got accepted into the leetcode, can someone please review and tell me if its a good idea to show this solution in an interview ?
    public static List combine(int n, int k) {
    List list = new ArrayList();
    for(int i=1; i

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

    I sent you an email🥰!!...
    Ep_11 _done 🥰🥰

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

    Need to watch it again