






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







Example:
5 different orderings = 5 different parenthesizations
Each parenthesization is a different number of mults Let Aij = Ai · · · Aj
Conclusion Order of operations makes a huge difference. How do we compute the minimum?
Parenthesization A product of matrices is fully parenthesized if it is either
Each parenthesization defines a set of n-1 matrix multiplications. We just need to pick the parenthesization that corresponds to the best ordering.
How many parenthesizations are there?
Structure of an optimal solution If the outermost parenthesization is
((A 1 A 2 · · · Ai)(Ai+1 · · · An)) then the optimal solution consists of solving A 1 i and Ai+1,n optimally and then combining the solutions.
Structure of an optimal solution If the outermost parenthesization is
((A 1 A 2 · · · Ai)(Ai+1 · · · An)) then the optimal solution consists of solving A 1 i and Ai+1,n optimally and then combining the solutions.
Proof: Consider an optimal algorithm that does not solve A 1 i optimally. Let x be the number of multiplications it does to solve A 1 i , y be the number of multiplications it does to solve Ai+1,n , and z be the number of multiplications it does in the final step. The total number of multiplications is therefore x + y + z. But since it is not solving A 1 i optimally, there is a way to solve A 1 i using x′^ < x multiplications. If we used this optimal algorithm instead of our current one for A 1 i , we would do
x′^ + y + z < x + y + z multiplications and therefore have a better algorithm, contradicting the fact that our algorithms is optimal.
In the enumeration of the P (n) = Ω(4n/n^3 /^2 ) subproblems, how many unique subproblems are there?
In the enumeration of the P (n) = Ω(4n/n^3 /^2 ) subproblems, how many unique subproblems are there?
Answer: A subproblem is of the form Aij with 1 ≤ i, j ≤ n , so there are O(n^2 ) subproblems!
Notation
If the final multiplication for Aij is Aij = AikAk+1,j then
m[i, j] = m[i, k] + m[k + 1, j] + pi− 1 pkpj.
We don’t know k a priori, so we take the minimum
m[i, j] =
0 if i = j , i^ min≤k<j{m[i, k] +^ m[k^ + 1, j] +^ pi−^1 pkpj}^ if^ i < j Direct recursion on this does not work! We must use the fact that there are at most O(n^2 ) different calls. What is the order?