About the subsequence

i dont understand value of i in this subsequence(a,n,i+1,j+1) function after function subsequence(a,n,i+1,j); i think value of i=3 when encounter null in this function but how we increment value of i in another function i.e subsequence(a,n,i+1,j+1);

Hello @manoj2597, we are incrementing the counter of i by i+1 in every function call as we are calling subsequence(a,n,i+1,j+1) or subsequence(a,n,i+1,j). And if we reach at i == 3 we will end up at the null character and then we will return the output.
I hope it is clear to you, incase if there is any confusion pls let me know.

i have doubt why value of i becomes 0 after encounter the null character in previous subsequence call in which we are not included ith character

and i start from 0 in another subsequence call

No, it doesn’t start with zero. It just goes 1 step backwards. Like when it reached at i = 3 then it will go back to 2 and then execute the second command.

i dont understand how it works

Take an example of “abc”
And we have two recursive calls,
subsequence(in,out,i+1,j+1)
subsequence(in,out,i+1,j)
Now what we need to do is,
we are starting from subsequence(in,out,0,0) where in the initial call in is “abc” and out is empty.
Now we are matching
out[j] = in[i] // and increment in to forward indexes
// calling subsequence(in,out,1,1) // here in is “abc” , out is “a”
// calling subsequence(in,out,2,2) // here in is “abc” , out is “ab”
// calling subsequence(in,out,3,3) // here in is “abc” , out is “abc”
And now we get the null condition and we will return it as the base condition.
Now we returned from the last recursive call that was, calling subsequence(in,out,3,3)
and now we need to call calling subsequence(in,out,3,2)
And so on this will go like this,
I hope it is clear to you.

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.