Consider the following array: {1, 3, 5, 8, 9, 2, 6, 7, 6} What is the minimum number of jumps required to reach the end of the array?
1
2
3
4
Answer and explanation
The jumps made will be:{1 -> 2 -> 4 -> 9}. So, the number of jumps is three.
ObjectiveMcq
Print Protected
This page is protected for print. Use the website to view the content.
Consider the following array: {1, 3, 5, 8, 9, 2, 6, 7, 6} What is the minimum number of jumps required to reach the end of the array?
1
2
3
4
The jumps made will be:{1 -> 2 -> 4 -> 9}. So, the number of jumps is three.
You are given an array of elements where each array element represents the MAXIMUM number of jumps that can be made in the forward direction from that element. You have to find the minimum number of jumps that are required to reach the end of the array. Which of these methods can be used to solve the problem?
Dynamic Programming
Greedy Algorithm
Recursion
Recursion and Dynamic Programming
Both recursion and dynamic programming can be used to solve minimum number of jumps problem.
Find the maximum sub-array sum for the following array: {3, 6, 7, 9, 3, 8}
33
36
23
26
All the elements of the array are positive. So, the maximum sub-array sum is equal to the sum of all the elements, which is 36.
Which method is used by line 4 of the above code snippet?
Divide and conquer
Recursion
Both memoization and divide and conquer
Memoization
The array "sum" is used to store the previously calculated values, so that they aren't recalculated. So, line 4 uses the memoization technique.
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})
The divide and conquer algorithm uses a constant space. So, the space complexity is O(1).
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})
The time complexity of the divide and conquer algorithm used to find the maximum sub-array sum is O(nlogn).
Which line should be inserted to complete the above code?
(tmp_max = cur_max)
break
continue
(cur_max = tmp_max)
If the tmp_max element is greater than the cur_max element, we make cur_max equal to tmp_max, i.e. (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
All the elements are negative. So, the maximum sub-array sum will be equal to the largest element. The largest element is -1 and therefore, the maximum sub-array sum is -1.
Find the maximum sub-array sum for the given elements. {2, -1, 3, -4, 1, -2, -1, 5, -4}
3
5
8
6
The maximum sub-array sum is 5.
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
Dynamic programming, naïve method and Divide and conquer methods can be used to solve the maximum sub array sum problem.
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];
The line arr[row][k] + arr[k + 1][col] + mat[row - 1] * mat[k] * mat[col] should be inserted to complete the above code.
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
The time complexity of finding all the possible ways of multiplying a set of n matrices is given by (n-1)^{th} Catalan number which is 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
The minimum number of multiplications required is 7750.
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
The minimum number of multiplications are 18000. This is the case when the matrices are parenthesized as (P*Q)*R.
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
The number of multiplications required is 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]).
The recurrence relation is given by:
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
Dynamic Programming, Brute force, Recursion methods can be used to solve the matrix chain multiplication problem.
Which of the following lines completes the above code?
strrev(str2)
str2 = str1
len2 = strlen(str2)
strlen(str2)
To find the longest palindromic subsequence, we need to reverse the copy of the string, which is done by strrev.
Longest palindromic subsequence is an example of ______________
Greedy algorithm
2D dynamic programming
1D dynamic programming
Divide and conquer
Longest palindromic subsequence is an example of 2D dynamic programming.