0% found this document useful (0 votes)
7 views12 pages

5.3 MCM

Uploaded by

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

5.3 MCM

Uploaded by

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

Department of Computer Science and Engineering (CSE)

UNIVERSITY INSTITUTE OF
ENGINEERING
COMPUTER SCIENCE ENGINEERING
Bachelor of Engineering
Design and Analysis of
Algorithms(CST-311/ITT-311)

Topic: Matrix Chain Multiplication DISCOVER . LEARN . EMPOWER

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Learning Objectives & Outcomes


Objective:
• To understand the concept of Matrix Chain Multiplication
using dynamic programming

Outcome:
• Student will understand
 Matrix Chain Multiplication using dynamic
programming.

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Matrix Chain Multiplication

• It is a Method under Dynamic Programming in which


previous output is taken as input for next.
• Here, Chain means one matrix's column is equal to the
second matrix's row [always].
• In general:
If A = ⌊aij⌋ is a p x q matrix
B = ⌊bij⌋ is a q x r matrix
C = ⌊cij⌋ is a p x r matrix
Then

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Example

• Let us have 3 matrices, A1,A2,A3 of order (10 x 100), (100 x


5) and (5 x 50) respectively.
Three Matrices can be multiplied in two ways:
 A1,(A2,A3): First multiplying(A2 and A3) then multiplying and resultant
withA1.
 (A1,A2),A3: First multiplying(A1 and A2) then multiplying and resultant
withA3.
• No of Scalar multiplication in Case 1 will be:
(100 x 5 x 50) + (10 x 100 x 50) = 25000 + 50000 = 75000
• No of Scalar multiplication in Case 2 will be:
(100 x 10 x 5) + (10 x 5 x 50) = 5000 + 2500 = 7500

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Number of ways for parenthesizing the matrices:


• There are very large numbers of ways of parenthesizing these
matrices. If there are n items, there are (n-1) ways in which the
outer most pair of parenthesis can place.
(A1) (A2,A3,A4,................An)
Or (A1,A2) (A3,A4 .................An)
Or (A1,A2,A3) (A4 ...............An)
........................

Or(A1,A2,A3.............An-1) (An)
• It can be observed that after splitting the kth matrices, we are
left with two parenthesized sequence of matrices: one consist
'k' matrices and another consist 'n-k' matrices.

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Development of Dynamic Programming Algorithm


• Characterize the structure of an optimal solution.
• Define the value of an optimal solution recursively.
• Compute the value of an optimal solution in a bottom-up
fashion.
• Construct the optimal solution from the computed
information.

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Algorithm

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Example

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

REFERENCES
Text books:
•Cormen, Leiserson, Rivest, Stein, “Introduction to Algorithms”, Prentice Hall of
India, 3rd edition 2012. problem, Graph coloring.

Websites:
• https://www.javatpoint.com/matrix-chain-multiplication-example

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Summary

Dynamic programming:

•Matrix Chain Multiplication

University Institute of Engineering (UIE)


THANK YOU

University Institute of Engineering (UIE)

You might also like