including and excluding case is not understand
how is execute properly please tell me my problem.
Subarray including and excluding case is not understand how is execute properly please tell me my problem
Basically
We are trying the include the present character once
so we first place the char in to the character array and then move both the pointer the input array pointer and o/p array pointer to the nxt loc
so
in[i] = out[j]
fn(in,out , i+1 , j+1)
if the curr element is not included just move the pointer to next position in the input char array keeping the pointer on the same pos in the o/p array.
this would help generate all possible subarrrays.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.
Hello Sahil, see first of all we need to tell the subsequences of the given string right.
So for abc it is
‘’ ‘a’ ‘ac’ ‘ab’ ‘abc’ ‘b’ ‘bc’ ‘c’ so in total 8 subsequences are there.
Now the inclusion exclusion case says that …
Suppose initially you have an empty string. And while considering exclusion case
that is fn(in,out , i+1 , j)
it means initially we are on a of abc and we don’t take it and move our i pointer and place it on b and again we exclude it and then we will come on c and now again we will exclude it so overall excluding all the elements it will result in an empty string.
Now we say we will include element a and exclude the rest of the elements so same using inclusion/exclusion we will have ‘a’ then excluded all the elements and next time we will get ‘ab’.
Similarly we will get all the subsequences.
Just take exclude condition as fn(in,out,i+1,j)
and include condition as
out[j] = in[i]
fn(in,out,i+1,j+1)
And pls try to dry run a small test case such as ‘a’ or ‘ab’ in recursion understanding with small testcases makes it easy to understand the concept.
I hope it is clear to you. In case it is clear to you pls mark it as resolve and provide the rating as well as feedback so that we can improve ourselves.
In case there is still some confusion pls let me know, I will surely try to help you out.
Thanks
Happy Coding !!
and
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.