Find the maximum sub-array sum for the following array: {3, 6, 7, 9, 3, 8}
33
36
23
26
157 practice sets · Page 2 of 8
Find the maximum sub-array sum for the following array: {3, 6, 7, 9, 3, 8}
33
36
23
26
Which method is used by line 4 of the above code snippet?
Divide and conquer
Recursion
Both memoization and divide and conquer
Memoization
What is the space complexity of the divide and conquer algorithm used to find the maximum sub-array sum?
O(n)
O(1)
O(n!)
O(n^{2})
What is the time complexity of the divide and conquer algorithm used to find the maximum sub-array sum?
O(n)
O(logn)
O(nlogn)
O(n^{2})
Which line should be inserted to complete the above code?
(tmp_max = cur_max)
break
continue
(cur_max = tmp_max)
Find the maximum sub-array sum for the given elements. {-2, -1, -3, -4, -1, -2, -1, -5, -4}
-3
5
3
-1
Find the maximum sub-array sum for the given elements. {2, -1, 3, -4, 1, -2, -1, 5, -4}
3
5
8
6
Given a one-dimensional array of integers, you have to find a sub-array with maximum sum. This is the maximum sub-array sum problem. Which of these methods can be used to solve the problem?
Dynamic programming
Two for loops (naive method)
Divide and conquer
Dynamic programming, naïve method and Divide and conquer methods
Which of the following lines should be inserted to complete the above code?
arr[row][k] - arr[k + 1][col] + mat[row - 1] * mat[k] * mat[col];
arr[row][k] + arr[k + 1][col] - mat[row - 1] * mat[k] * mat[col];
arr[row][k] + arr[k + 1][col] + mat[row - 1] * mat[k] * mat[col];
arr[row][k] - arr[k + 1][col] - mat[row - 1] * mat[k] * mat[col];
Consider the brute force implementation in which we find all the possible ways of multiplying the given set of n matrices. What is the time complexity of this implementation?
O(n!)
O(n^{3})
O(n^{2})
Exponential
Consider the matrices P, Q, R and S which are 20 x 15, 15 x 30, 30 x 5 and 5 x 40 matrices respectively. What is the minimum number of multiplications required to multiply the four matrices?
6050
7500
7750
12000
Consider the matrices P, Q and R which are 10 x 20, 20 x 30 and 30 x 40 matrices respectively. What is the minimum number of multiplications required to multiply the three matrices?
18000
12000
24000
32000
Consider the two matrices P and Q which are 10 x 20 and 20 x 30 matrices respectively. What is the number of multiplications required to multiply the two matrices?
10*20
20*30
10*30
102030
Which of the following is the recurrence relation for the matrix chain multiplication problem where mat[i-1] * mat[i] gives the dimension of the ith matrix?
dp[i,j] = 1 if (i=j dp[i,j] = min{dp[i,k] + dp[k+1,j]})
dp[i,j] = 0 if (i=j dp[i,j] = min{dp[i,k] + dp[k+1,j]})
dp[i,j] = 1 if (i=j dp[i,j] = min{dp[i,k] + dp[k+1,j]} + mat[i-1]*mat[k]*mat[j]).
dp[i,j] = 0 if (i=j dp[i,j] = min{dp[i,k] + dp[k+1,j]} + mat[i-1]*mat[k]*mat[j]).
Which of the following methods can be used to solve the matrix chain multiplication problem?
Dynamic programming
Brute force
Recursion
Dynamic Programming, Brute force, Recursion
Which of the following lines completes the above code?
strrev(str2)
str2 = str1
len2 = strlen(str2)
strlen(str2)
Longest palindromic subsequence is an example of ______________
Greedy algorithm
2D dynamic programming
1D dynamic programming
Divide and conquer
For every non-empty string, the length of the longest palindromic subsequence is at least one.
True
False
What is the time complexity of the brute force algorithm used to find the length of the longest palindromic subsequence?
O(1)
O(2^{n})
O(n)
O(n^{2})
What is the length of the longest palindromic subsequence for the string "ababcdabba"?
6
7
8
9