Examveda

The recursive formula for Catalan number is given by Cn = ∑Ci*C(n-i).
Consider the following dynamic programming implementation for Catalan numbers:
#include<stdio.h>
int cat_number(int n)
{
     int i,j,arr[n],k;
     arr[0] = 1;
     for(i = 1; i < n; i++)
     {
         arr[i] = 0;
         for(j = 0,k = i - 1; j < i; j++,k--)
           ______________________;
     }
     return arr[n-1];
 
}
int main()
{
     int ans, n = 8;
     ans = cat_number(n);
     printf("%d\n",ans);
     return 0;
}
Which of the following lines completes the above code?

A. arr[i] = arr[j] * arr[k];

B. arr[j] += arr[i] * arr[k];

C. arr[i] += arr[j] * arr[k].

D. arr[j] = arr[i] * arr[k];

Answer: Option C


Join The Discussion

Related Questions on Dynamic Programming in Data Structures