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.
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 )
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.
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
Bhaiya aapke Recursion ka video Dekh ke lagta hai ki, Sare Data Structure Chor Ke Kewal Recursion hi Padhu. It's amazing videos ❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤
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 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
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.
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)
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.
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
''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)
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.
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/-
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.
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.
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)
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
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 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.
@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.
--> 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
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.
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
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.
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
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
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
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.
Really.........Now I would start enjoying with Recursion from when Fraz bhaiya would start teaching about Recursion!!......Thanks alot bhaiya!!
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 )
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.
I think space complexity will also be O2^n as in worst case 2^n recursion calls will be stored in recursion call stack
for recurtion its n and for prepareing the final result 2d array its 2^n
Really enjoyed solving the problem together.
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
amazing explanation bhaiya because of you I am loving recursion
Bhaiya aapke Recursion ka video Dekh ke lagta hai ki,
Sare Data Structure Chor Ke Kewal Recursion hi Padhu.
It's amazing videos ❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤
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
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💔
@@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
@@arghya_0802 i will wait for your summary comment🥰 i totally new.. Its very beneficial for me❣️ thank u
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.
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)
lecture 11 done 😍😍😍👌👌🤞 waiting for the next episode 🖤🖤🖤🖤
i like your apriciation bhaiya
This series is verry helpfull and i read verry more understanding so i will place in 30 days. ❤🔥❤🔥❤🔥❤🔥
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.
Algo : 3:30
Code : 10:30
Optimization : 17:50
Day 11 done ✅✅
Mast tha 🙂
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
wonderful explanation recursion looking easy
Bro excellent lecture again and the intuition behind the question helps me to get the question done by me without seeing the solution ❤❤❤❤❤❤❤❤❤❤❤❤❤❤
Thankyou bhaiya for this session
1.base case
2.take the element
3.backtrack
4.ignore the element
Done Understood❤✅
Very nice explanation , thanks
''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)
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.
Good Explaination bro,
i tried and succeed,
Consistency✌✌ #Day11
Need to watch it again
Day 11
aaj itna jaldi post 🔥🔥
Thanks Fraz for the entire recursion series.
Thanks for the lectures and all your efforts sir🧡🧡🧡🧡🧡
#EP_11 completed
Consistency_OP 🔥🔥🔥
Summarize
first is the genrate all the posible and recuired subset and other is the efficient base case and bounded condition.
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/-
Day 11 Done bhaiya👍
How many lectures for recursion are remaining? Please please tell
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.
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.
Kal iss sem ka last exam hai But still I am watching videos 😍
Complete Day 11 ❤️
Good Video
Nice explanation 👌
yes done day 11 🙌❤️
Bhot zbrdst
Nice explain.
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)
Lecture 11 Done ☑
#dsabyfaraz🌠
How many more recursion lectures?
7 may be
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
Thankyou bhaiya.
Complete and conquer..
In the last base condition where we're avoiding very short subsets, the base condition should be (subset.size()+n-i+1 < k)
Thanks bhaiya
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)
who told u in cpp constraints dont bother people?
@@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.
Thank you so so much Fraz Bhaiya for your every efforts towards us✨❤
Episode 11 done! 🔥🔥
Great video😀
done for day 11😊
thank you
11 Done ✅
Episode -11 Completed
Nice
Make video for vector concept I got error while try to run the code on another compiler
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
@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.
@Ayush Chopra It will keep track of every subset by backtracking.
Great
Present ! ✅🙌
--> 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
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.
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 ?
BSc se hoon big product company ke liye pay after placement program OR MCA from local colleges ?
Bhaiya beginner DSA series kab aayegi pls 🙏 reply krna
Exam in 2 days now i am watching it with 2× speed....😅😅😅
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
can you please dry run this whole code, not the recursion tree but every iteration?
Where can I practice questions on recursion...or watching your lectures are enough??
May you explain the python code please?
Consistency ++
pls tell me how you will find remainingelements = n-i+1 ?
Done✅
Bro...in your journey...on you first go...did u solve generating permutations.. generating subsets kind of problems.?
baas video dekhte jaa thode din baad samaj ayega ye topic kyu choose kiye tha
@@vinodthakar4561 please say in English...I don't know hindi
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.
Syllabus of tomorrow's contest bhaiya?
🔥🔥🔥🔥❣️
more video
How is n-i+1 remaining elements?
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
Isn’t the complexity k*2^n ?
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
First
Thanks ☺️❤️
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
Yahi to hustle hai.
Karo ye sab
ye sb choti chiz se Darna nhi h . Remember one thing "Jab tk todenge nhi tbtk chhodenge nhi"😅😅
These are subsequences, not subsets.
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
I sent you an email🥰!!...
Ep_11 _done 🥰🥰
Need to watch it again