Question
Assume that multiplying a matrix of dimension with another matrix of dimension requires scalar multiplications. Computing the product of matrices can be done by parenthesizing in different ways. Define as an explicitly computed pair for a given parenthesization if they are directly multiplied. For example, in the matrix multiplication chain using parenthesization , and are the only explicitly computed pairs.
Consider a matrix multiplication chain , where matrices and are of dimensions , , , and , respectively. In the parenthesization of that minimizes the total number of scalar multiplications, the explicitly computed pairs is/are
Official answer and solution
- Official answer
- C
- From
- Official GATE 2018 answer key
Solution
Use dynamic programming for matrix chain multiplication to find the parenthesization that minimizes scalar multiplications.
Given matrix dimensions for matrices :
Compute costs for subchains:
- Chain length 2:
- :
- :
- :
- :
- Chain length 3:
- :
- : (split at )
- :
- Chain length 4:
- : with structure
- Chain length 5 ():
- Split : .
- Any split involving earlier incurs much higher costs (e.g., alone is 16000).
The optimal parenthesization is with total cost 2173.
In this parenthesization, the only base matrices multiplied directly together without an intermediate product are and ().
C
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2018 Computer Science and Information Technology (CS)
- Question
- 41 of 65, printed as CS Q.31
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.