for e.g abc is the input and we take a ab and then abc but after printing abc how it goes to ab ?
I am stuck in this
Doubt regarding how recursion goes backward
@navin_japes,
F(a) calls F(ab) which then calls F(abc),
Now in F(abc), we hit the base case and print “abc” followed by a return statement.
After the return statement, the control comes back to F(ab) which does rest of its recursions, eventually returning back to F(a).
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.
How it goes without setting the i value to i-1 and after finishing how it goes to right that also is not clear
@navin_japes,
When F(i-1) asks for result from F(i), its call is stored in a stack called recursion stack, so when execution of F(i) is finished, the control is given back to the top element of the recursion stack( which here is F(i-1) ), and thus F(i-1) gains control again.
For going “right” F(i-1) calls F(i) i,e the recursion you wrote in your code.