6 Matrix Chain M Ultiplication
6 Matrix Chain M Ultiplication
• Here no. of Column of first matrix are equal to the no. of Rows of
second matrix.
• So, we talk about dimension it will be:
2x3x2
(A1XA2)XA3 A1X(A2XA3)
1. A1(A2(A3XA4))
2. A1((A2XA3)A4)
3. (A1XA3)(A3XA4)
4. (A1(A2XA3))A4
5. ((A1XA2)A3)A4
Design and Analysis of Algorithm 10
Matrix Chain Multiplication
• To find the best possible way to calculate the product, we could simply
parenthesis the expression in every possible fashion and count each
time how many scalar multiplication are required.
• Matrix Chain Multiplication Problem can be stated as "find the optimal
parenthesization of a chain of matrices to be multiplied such that the
number of scalar multiplication is minimized".
Number of ways for parenthesizing the matrices:
?
16
Design and Analysis of Algorithm
Matrix Chain Multiplication
Step 3: Computing Optimal Costs: let us assume that matrix
Ai has dimension pi-1x pi for i=1, 2, 3....n. The input is a sequence
(p0,p1,......pn) where length [p] = n+1. The procedure uses an
auxiliary table m [1....n, 1.....n] for storing m [i, j] costs an auxiliary
table s [1.....n, 1.....n] that record which index of k achieved the
optimal costs in computing m [i, j].