GATE 2015 CS (CS2) – Question 24
Find fun(5).
int fun(int n) {
int x=1,k;
if (n==1) return x;
for (k=1;k<n;++k)
x=x+fun(k)*fun(n-k);
return x;
}Practise this question in The GATE Grind →
Show answer and explanation
Correct answer: 51
Explanation
Let F(n) be the returned value. F(1)=1 and F(n)=1+Σ F(k)F(n−k). Consequently F(2)=2, F(3)=1+2+2=5, and F(4)=1+5+4+5=15. Then F(5)=1+15+10+10+15=51.