JB TAK FODEGA NHI .... TB TK CHODEGA NHI .... (MAANG)

L7 All Kind of Patterns in Recursion

In this Lecture we learn all about the Different-Different pattern based on Recursion In the prevesely lecture we know in depth all about the Subsecquance in depth

P1 Print All the Subsequence whos Sum is Equal to the K

in this Problem our task is print all the Subsecquance that sum is == to the k or given Sum

Example 1:
Input: nums = [1,2,1],Sum = 2
Output: [1,1],[2]

  • Again we used the concept of the Pick and Not Pick and check is Sum fo the subsecquance is equal to the given k store that particular subsecquance in the DS.

  • Sudo Code


    Recursion Tree


    Notes

    Note: Zoom for Better Understanding



    Code Zone!

    Recursion Python Code
    Recursion Java Code
    Recursion C++ Code
    Sb Mai He Kru ...

    Khud Bhi Kr le Khuch ..... Nalayk


    Time Complexity:O(2 ^ N) For every Iteration we have tuple of option take or not take Exponintial Time
    Space Complexity:O(N)+O(N) O(N) for the Recursive Stack Space and O(N) for Store the our element that is our Subsecquances.

    P2 Print Only One Subsequence whos Sum is Equal to the K

    This is the Modifiyed problem of the Preveous One in this Problem our task is only find the Single Subsequence and Stop the Iteration.

    Sudo Code


    Code Zone!

    Recursion Python Code
    Recursion Java Code
    Recursion C++ Code
    Sb Mai He Kru ...

    Khud Bhi Kr le Khuch ..... Nalayk


    Time Complexity:O(2 ^ N) For every Iteration we have tuple of option take or not take Exponintial Time
    Space Complexity:O(N)+O(N) O(N) for the Recursive Stack Space and O(N) for Store the our element that is our Subsecquances.

    P3 Total Count the Subsequence whos Sum is Equal to the K

    This is Agian the Modifiyed problem of the Preveous One in this Problem our task is only count the Number of the Subsecquance that Sum is == K

  • Again we used the concept of the Pick and Not Pick and check is Sum fo the subsecquance is equal to the given k
  • Preversely We Maintain the Array for count the Element that Sum is Equal to the k and that array print it.
  • But here we used at the Palced of the Array used a Variable for Cout the Subsecquance

  • Sudo Code


    Recursion Tree
    Complete Tree in the Notes

    Code Zone!

    Recursion Python Code
    Recursion Java Code
    Recursion C++ Code
    Sb Mai He Kru ...

    Khud Bhi Kr le Khuch ..... Nalayk


    Time Complexity:O(2 ^ N) For every Iteration we have tuple of option take or not take Exponintial Time
    Space Complexity:O(N) O(N) for the Recursive Stack Space.


    Color
    Background
    Interview Docs File "All the Best" Team @DSAwithPrinceSingh

    ~ It's All About Consistency📈 Dedication🎯 HardWork💪 Happy Coding❤️ ~