This question is about dynamic programming for Matrix Chain Multiplication, where we want
to determine the minimum number of scalar multiplications necessary to compute a product
A1 A2... An of n matrices A1, A2,..., An.
(a) For $n_A, m_A, n_B, m_B \in \mathbb{N}\{0\}$, let A be an ($n_A \times m_A$)-matrix and let B be an ($n_B \times m_B$)-
matrix. Which condition on $n_A, m_A, n_B, m_B$ needs to be satisfied so that the matrices
A and B can be multiplied (i. e. the product A \cdot B exists)? What is the size of the
resulting matrix A \cdot B?
[2 marks]
(b) Describe the dynamic programming algorithm for Matrix Chain Multiplication by an-
swering questions (i)-(iv).
Recall that for all $i, k$ with $1 \le i \le k \le n$ we compute the minimum number $M[i, k]$ of
multiplications necessary to compute $A_i \cdots A_k$, where
$M[i, i] = 0$ for all $i$ with $1 \le i \le n$
$M[i, k] = \min\{M[i, j] + d_{i-1}d_j d_k + M[j + 1, k] \mid i < j < k\}$ for all $i, k$ with $1 \le i < k \le n$.
(i) What are the input and the output?
(ii) What are the numbers $d_j$ in the above recurrence?
(iii) Which numbers are computed in intermediate steps and how?
(iv) How can the optimal position of the brackets be determined?
(v) What is the asymptotic running time and why?
[10 marks]
(c) Execute your algorithm for four matrices A1 A2 A3 A4, where A1 is a (2 x 3)-matrix,
A2 is a (3 x 6)-matrix, A3 is a (6 x 4)-matrix, and A4 is a (4 x 5)-matrix. Copy the table
below and fill in the intermediate results. Determine the minimum number of scalar
multiplications and the corresponding positions of the brackets.
$i = 1$
$i = 2$
$i = 3$
$i = 4$
$k = 1$ $k = 2$ $k = 3$ $k = 4$
[8 marks]