0% found this document useful (0 votes)
41 views11 pages

Matrix Chain Multiplication Problem

The document discusses the matrix chain multiplication problem. It provides an example of multiplying several matrices together (5x4, 4x6, 6x2, 2x7) and calculating the costs (number of operations) for multiplying subsets of the matrices in different orders. It shows filling a table with the costs, and explains how to systematically calculate the costs for multiplying each pair and subset of matrices in the chain using the previously calculated values. The goal is to find the order that minimizes the total cost of multiplying all the matrices.

Uploaded by

prachi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views11 pages

Matrix Chain Multiplication Problem

The document discusses the matrix chain multiplication problem. It provides an example of multiplying several matrices together (5x4, 4x6, 6x2, 2x7) and calculating the costs (number of operations) for multiplying subsets of the matrices in different orders. It shows filling a table with the costs, and explains how to systematically calculate the costs for multiplying each pair and subset of matrices in the chain using the previously calculated values. The goal is to find the order that minimizes the total cost of multiplying all the matrices.

Uploaded by

prachi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Matrix Chain

Multiplication Insert or Drag &

Problem

Prachi Joshi
Recalling Matrix Multiplication
5*4 4*6 6*2 2*7

1 2 3 4
1 0
2 0
3 0
4 0

For just A1 Cost is 0. m[1,1]=0


For just A2 Cost is 0 m[2,2]=0
For just A3 Cost is 0 m[3,3]=0
For just A4 Cost is 0 m[4,4]=0
5*4 4*6 6*2 2*7

Find m[1,2] = A1 . A2
= (5*4) (4*6)
= 5*4*6 1 2 3 4
= 120 1 0 120
2 0
3 0
4 0
5*4 4*6 6*2 2*7

Find m[2,3] = A2 . A3
= (4*6) (6*2)
= 4*6*2 1 2 3 4
= 48 1 0 120
2 0 48
3 0
4 0
5*4 4*6 6*2 2*7

Find m[3,4] = A3 . A4
= (6*2) (2*7)
= 6*2*7 1 2 3 4
= 84 1 0 120
2 0 48
3 0 84
4 0
Find m[1,3] = Two ways, take the minimum
5*4 4*6 6*2 2*7
Way 1
A1 . (A2 . A3)
5*4 4*6 6*2
=m[1,1]+m[2,3]+5*4*2
=0+48+40
=88 1 2 3 4
1 0 120 88
Way 2 2 0 48
(A1 . A2) . A3 3 0 84
5*4 4*6 6*2
4 0
=m[1,2]+m[3,3]+5*6*2
=120+0+60
=180
Find m[2,4] = Two ways, take the minimum
5*4 4*6 6*2 2*7
Way 1
A2 . (A3 . A4)
4*6 6*2 2*7
=m[2,2]+m[3,4]+4*6*7
=0+84+168
=252 1 2 3 4
1 0 120 88
Way 2 2 0 48 104
(A2 . A3) . A4 3 0 84
4*6 6*2 2*7
4 0
=m[2,3]+m[4,4]+4*2*7
=48+0+56
=104
5*4 4*6 6*2 2*7
Find m[1,4] Use the following formula

m[1,4]=min{m[1,1]+m[2,4]+5*4*7, m[1,2]+m[3,4]+5*6*7,
m[1,3]+m[4,4]+5*2*7}

=min{0+104+140,120+84+210,88+0+70}

=min{244,414,158} 1 2 3 4
1 0 120 88 158
=158
2 0 48 104
3 0 84
4 0
1
4 2
158
1 2 3 4 104 3
1 0 120 88 158 3 88 4
84
2 0 48 104 48 0
2
3 0 84 120 0
0
4 0 1
0

You might also like