Question
Consider the following dynamic programming implementation for Catalan numbers. Which of the following lines completes the below code?
#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;
}
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];
Posted under Data Structures and Algorithms
Engage with the Community - Add Your Comment
Confused About the Answer? Ask for Details Here.
Know the Explanation? Add it Here.
Q. The recursive formula for Catalan number is given by Cn = ∑Ci*C(n-i). Consider the following dynamic programming implementation for Catalan numbers. Which of the following lines...
Similar Questions
Discover Related MCQs
Q. Which of the following implementations of Catalan numbers has the smallest time complexity?
View solution
Q. Which of the following implementations of Catalan numbers has the largest space complexity(Don’t consider the stack space)?
View solution
Q. Which of the following methods can be used to solve the assembly line scheduling problem?
View solution
Q. What is the time complexity of the brute force algorithm used to solve the assembly line scheduling problem?
View solution
Q. In the dynamic programming implementation of the assembly line scheduling problem, how many lookup tables are required?
View solution
Q. Given a string, you have to find the minimum number of characters to be inserted in the string so that the string becomes a palindrome. Which of the following methods can be used to solve the problem?
View solution
Q. In which of the following cases will the number of insertions to form a palindrome be minimum?
View solution
Q. In the worst case, the minimum number of insertions to be made to convert the string into a palindrome is equal to the length of the string.
View solution
Q. Consider the string “efge”. What is the minimum number of insertions required to make the string a palindrome?
View solution
Q. Consider the string “abbccbba”. What is the minimum number of insertions required to make the string a palindrome?
View solution
Q. Which of the following problems can be used to solve the minimum number of insertions to form a palindrome problem?
View solution
Q. Given a 2D matrix, find a submatrix that has the maximum sum. Which of the following methods can be used to solve this problem?
View solution
Q. In which of the following cases, the maximum sum rectangle is the 2D matrix itself?
View solution
Q. In which of the following cases, the maximum sum rectangle can be a 1 x 1 matrix containing the largest element?
View solution
Q. Consider a matrix in which all the elements are non-zero(at least one positive and at least one negative element). In this case, the sum of the elements of the maximum sum rectangle cannot be zero.
View solution
Q. Consider the 2×3 matrix {{1,2,3},{1,2,3}}. What is the sum of elements of the maximum sum rectangle?
View solution
Q. Consider the 2×2 matrix {{-1,-2},{-3,-4}}. What is the sum of elements of the maximum sum rectangle?
View solution
Q. Consider the 3×3 matrix {{2,1,-3},{6,3,4},{-2,3,0}}. What is the sum of the elements of the maximum sum rectangle?
View solution
Q. What is the time complexity of the brute force implementation of the maximum sum rectangle problem?
View solution
Q. The dynamic programming implementation of the maximum sum rectangle problem uses which of the following algorithm?
View solution
Suggested Topics
Are you eager to expand your knowledge beyond Data Structures and Algorithms? We've curated a selection of related categories that you might find intriguing.
Click on the categories below to discover a wealth of MCQs and enrich your understanding of Computer Science. Happy exploring!