Answer: 51
Let T(n) denote the return value of fun(n). We can analyze the function and write the recurrence relation for T(n) as follows:
- For n=1, the base case is triggered:
T(1)=1
- For n>1, the loop calculates:
T(n)=1+∑k=1n−1T(k)⋅T(n−k)
Let us compute the values step-by-step:
- For n=2:
T(2)=1+T(1)⋅T(1)=1+(1⋅1)=2
- For n=3:
T(3)=1+T(1)⋅T(2)+T(2)⋅T(1)=1+(1⋅2)+(2⋅1)=5
- For n=4:
T(4)=1+T(1)⋅T(3)+T(2)⋅T(2)+T(3)⋅T(1)=1+(1⋅5)+(2⋅2)+(5⋅1)=15
- For n=5:
T(5)=1+T(1)⋅T(4)+T(2)⋅T(3)+T(3)⋅T(2)+T(4)⋅T(1)
T(5)=1+(1⋅15)+(2⋅5)+(5⋅2)+(15⋅1)
T(5)=1+15+10+10+15=51
Thus, the return value of fun(5) is 51.