Data Structure Multiple Choice Questions on “Matrix-chain Multiplication”.
1. Which of the following methods can be used to solve the matrix chain multiplication problem? Answer: d 2. 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? Answer: d 3. 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? Answer: d 4. 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? Answer: a 5. 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? 6. 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? 7. Consider the following dynamic programming implementation of the matrix chain problem: Which of the following lines should be inserted to complete the above code? Answer: c 8. What is the time complexity of the following dynamic programming implementation of the matrix chain problem? a) O(1) Answer: d 9. What is the space complexity of the following dynamic programming implementation of the matrix chain problem? a) O(1) Answer: c 10. What is the output of the following code? a) 64000 Answer: a 11. What is the value stored in arr[2][3] when the following code is executed? a) 64000 Answer: b 12. What is the output of the following code? a) 2000 Answer: c 13. What is the output of the following code? a) 32000 Answer: c
a) Dynamic programming
b) Brute force
c) Recursion
d) Dynamic Programming, Brute force, Recursion
Clarification: Dynamic Programming, Brute force, Recursion methods can be used to solve the matrix chain multiplication problem.
a) dp[i,j] = 1 if i=j
dp[i,j] = min{dp[i,k] + dp[k+1,j]}
b) dp[i,j] = 0 if i=j
dp[i,j] = min{dp[i,k] + dp[k+1,j]}
c) 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].
d) 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].
Clarification: 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].
a) 10*20
b) 20*30
c) 10*30
d) 10*20*30
Clarification: The number of multiplications required is 10*20*30.
a) 18000
b) 12000
c) 24000
d) 32000
Clarification: The minimum number of multiplications are 18000. This is the case when the matrices are parenthesized as (P*Q)*R.
a) 6050
b) 7500
c) 7750
d) 12000
Answer: c
Clarification: The minimum number of multiplications required is 7750.
a) O(n!)
b) O(n3)
c) O(n2)
d) Exponential
Answer: d
Clarification: 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.#include
a) arr[row][k] – arr[k + 1][col] + mat[row – 1] * mat[k] * mat[col];
b) arr[row][k] + arr[k + 1][col] – mat[row – 1] * mat[k] * mat[col];
c) arr[row][k] + arr[k + 1][col] + mat[row – 1] * mat[k] * mat[col];
d) arr[row][k] – arr[k + 1][col] – mat[row – 1] * mat[k] * mat[col];
Clarification: The line arr[row][k] + arr[k + 1][col] + mat[row – 1] * mat[k] * mat[col] should be inserted to complete the above code.#include
b) O(n)
c) O(n2)
d) O(n3)
View Answer
Clarification: The time complexity of the above dynamic programming implementation of the matrix chain multiplication is O(n3).#include
b) O(n)
c) O(n2)
d) O(n3)
Clarification: The space complexity of the above dynamic programming implementation of the matrix chain multiplication is O(n2).#include
b) 70000
c) 120000
d) 150000
Clarification: The program prints the minimum number of multiplications required, which is 64000.#include
b) 60000
c) 24000
d) 12000
Clarification: The value stored in arr[2][3] when the above code is executed is 60000.#include
b) 3000
c) 4000
d) 5000
View Answer
Clarification: The program prints the minimum number of multiplications required to multiply the given matrices, which is 4000.#include
b) 28000
c) 64000
d) 70000
View Answer
Clarification: The output of the program is 64000.