The language is C.
What is function(9)? Use a recursion tree to find the answer.
int function(int n) {
If (n<=1)
return 1;
If (n%2==0)
return f(n/2);
return f(n/2) + f((n/2)+1);
}
Ans --> On giving n=9 the first two conditions in if statements will be false so last statement will be executed which will give call to f(4)+f(5) and these two will be evaluated individually which i am providing with tree diagram.
In order to support my answer i have implemented the same function which i am providing you screenshot of code along with output.
Get Answers For Free
Most questions answered within 1 hours.