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]
Sudo Code
Recursion Tree
Notes
Note: Zoom for Better Understanding
Code Zone!
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!
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
Sudo Code
Recursion Tree
Complete Tree in the Notes
Code Zone!
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.