Consider the following C function. int fun(int n) { int x=1, k; if (n==1) return x; for (k=1; k The return value of fun(5) is …
Topic-wise GATE CS PYQs with verified steps
GATE CSE 2015 Set 2 · Q11
Time
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;
}The return value of fun(5) is _______.Your answerNumerical answer
Solution
Official answer: 51
RecursionWe can compute the value returned by fun(n) recursively for increasing values of :
For :
The base condition if (n == 1) triggers, returning:
For : Initially .
For :
For : Initially .
For :
For :
For : Initially .
For :
For :
For :
For : Initially .
For :
For :
For :
For :
Thus, the return value of fun(5) is 51.
Try the question first, then check your work.
Examiner trap
Calculate the return values sequentially for and use them to evaluate fun(5).
This Recursion previous year question is Q11 of the GATE CSE 2015 Set 2 paper. Find more GATE CSE PYQs on Recursion in Programming and Data Structures, or browse all GATE CSE PYQs.
Free diagnostic
Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Recursion PYQs now with no account.
An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.
Recursion has 19 GATE CSE PYQs across 15 papers from 2011 to 2026. 2 of them are 1-mark NAT questions like this one, and GATE CSE 2015 Set 2 has 2.
How GATE tests RecursionIndependent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.