Find an optimal parenthesization of a matrix-chain product whose sequence of dimensions is
$\left \langle 5, 10, 3, 12, 5, 50, 6 \right \rangle$ .
Table
1 | 2 | 3 | 4 | 5 | 6 | |
---|---|---|---|---|---|---|
1 | 0 | 150 | 330 | 405 | 1655 | 2010 |
2 | 0 | 360 | 330 | 2430 | 1950 | |
3 | 0 | 180 | 930 | 1770 | ||
4 | 0 | 3000 | 1860 | |||
5 | 0 | 1500 | ||||
6 | 0 |
Table
1 | 2 | 3 | 4 | 5 | 6 | |
---|---|---|---|---|---|---|
1 | 1 | 2 | 2 | 4 | 2 | |
2 | 2 | 2 | 2 | 2 | ||
3 | 3 | 4 | 4 | |||
4 | 4 | 4 | ||||
5 | 5 | |||||
6 |
Optimal parenthesization:
Give a recursive algorithm MATRIX-CHAIN-MULTIPLY$(A, s, i, j)$ that actually performs the optimal matrix-chain multiplication, given the sequence of matrices
$\langle A_1, A_2, \dots ,A_{n_i} \rangle$ , the$s$ table computed by MATRIX-CHAIN-ORDER, and the indices$i$ and$j$ . (The initial call would be MATRIX-CHAIN-MULTIPLY$(A, s, 1, n)$.)
MATRIX-CHAIN-MULTIPLY(A, s, i, j)
1 if i == j
2 return A[i]
3 if i + 1 == j
4 return A[i] * A[j]
5 b = MATRIX-CHAIN-MULTIPLY(A, s, i, s[i, j])
6 c = MATRIX-CHAIN-MULTIPLY(A, s, s[i, j] + 1, j)
7 return b * c
Use the substitution method to show that the solution to the recurrence (15.6) is
$\Omega(2^n)$ .
Suppose
Describe the subproblem graph for matrix-chain multiplication with an input chain of length
$n$ . How many vertices does it have? How many edges does it have, and which edges are they?
Vertice:
Let
$R(i, j)$ be the number of times that table entry$m[i, j]$ is referenced while computing other table entries in a call of MATRIX-CHAIN-ORDER. Show that the total number of references for the entire table is
$\displaystyle \sum_{i=1}^n \sum_{j=i}^n R(i, j) = \frac{n^3 - n}{3}$ .
Show that a full parenthesization of an
$n$ -element expression has exactly$n-1$ pairs
of parentheses.