About recursion

what happens when there two recursive calls one above another. I am having great difficulty in recursion .please help!!

first the control goes to the first call executes it completely and then when it returns back to the calling function, then it goes to the second call and executes it.

please explain me with the help of any problem.

int f1(int x)
{
if(x <= 0 || x > 2) return;
System.out.println(x);
f1(x - 1);
f1(x - 2);
}

This piece of code on passing x = 2 as input should produce output:
2
1

First the control enters with x = 2 and then goes for f1(x = 1) and then for f1(x = 0) and then for f1(x = -1) and then for f1(x = 0) again.

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.

please explain me with the help of binary tree having say just the three nodes . Actually I am stuck with the statements like:
say a simple program -->
int height(node* root)
{
if root==NULL
return;
}
int left=height(root->left);
int right=height(root->right);
return max(left,right)+1;
please explain me with the dry run especially part where the two recursive calls are made one after another.

the first line enters into the left subtree and calculates the answer for it and returns the height for it , similarly for the right subtree. I suggest you print out the values for each node while it enters and exits the height funtion and that would make it all clear to you.