Matrix Chain Multiplication
Matrix Chain Multiplication
Say What?
◦ If (A (B ((CD) (EF)) ) ) is optimal
◦ Then (B ((CD) (EF)) ) is optimal as well
◦ Proof on the next slide…
Matrix Chain Multiplication
Assume that we are calculating ABCDEF and that
the following parenthesization is optimal:
(A (B ((CD) (EF)) ) )
◦ Then it is necessarily the case that
(B ((CD) (EF)) )
◦ is the optimal parenthesization of BCDEF.
Why is this?
◦ Because if it wasn't, and say ( ((BC) (DE)) F) was
better, then it would also follow that
(A ( ((BC) (DE)) F) ) was better than
(A (B ((CD) (EF)) ) ),
◦ contradicting its optimality!
Matrix Chain Multiplication
Our final multiplication will ALWAYS be of the form
◦ (A0 A1 ... Ak) (Ak+1 Ak+2 ... An-1)