Download presentation
Presentation is loading. Please wait.
1
Catalan Numbers
2
Multiplying n Numbers n multiplication order 2 (x1 · x2) 3
(x1 · (x2 · x3)) ((x1 · x2) · x3) 4 (x1 · (x2 · (x3 · x4))) (x1 · ((x2 · x3) · x4)) ((x1 · x2) · (x3 · x4)) ((x1 · (x2 · x3)) · x4) (((x1 · x2) · x3) · x4) Objective: Find C(n), the number of ways to compute product x1 . x2 …. xn.
3
Multiplying n Numbers – small n
C(n) 1 2 3 4 5 14 6 42 7 132
4
Chain-Matrix Multiplication
Dr Nazir A. Zafar Advanced Algorithms Analysis and Design
5
Problem Statement: Chain Matrix Multiplication
Statement: The chain-matrix multiplication problem can be stated as below: Given a chain of [A1, A2, , An] of n matrices where for i = 1, 2, , n, matrix Ai has dimension pi-1 x pi, find the order of multiplication which minimizes the number of scalar multiplications. Note: Order of A1 is p0 x p1, Order of A2 is p1 x p2, Order of A3 is p2 x p3, etc. Order of A1 x A2 x A3 is p0 x p3, Order of A1 x A2 x x An is p0 x pn
6
Chain Matrix Multiplication
(Brute Force Approach)
7
Brute Force Chain Matrix Multiplication
Example Given a sequence [A1, A2, A3, A4] Order of A1 = 10 x 100 Order of A2 = 100 x 5 Order of A3 = 5x 50 Order of A4 = 50x 20 Compute the order of the product A1 . A2 . A3 . A4 in such a way that minimizes the total number of scalar multiplications.
8
Brute Force Chain Matrix Multiplication
There are five ways to parenthesize this product Cost of computing the matrix product may vary, depending on order of parenthesis. All possible ways of parenthesizing (A1 · (A2 . (A3 . A4))) (A1 · ((A2 . A3). A4)) ((A1 · A2). (A3 . A4)) ((A1 · (A2 . A3)). A4) (((A1 · A2). A3). A4)
9
Kinds of problems solved by algorithms
10
Second Chain : (A1 · ((A2 . A3). A4))
11
Third Chain : ((A1 · A2). (A3 . A4))
12
Fourth Chain : ((A1 · (A2 . A3)). A4)
Dr Nazir A. Zafar Advanced Algorithms Analysis and Design
13
Fifth Chain : (((A1 · A2). A3). A4)
14
Chain Matrix Cost ((A1 · A2). (A3 . A4)) First Chain 35,000
Second Chain 145,000 Third Chain 11,000 Fourth Chain 85,000 Fifth Chain 17,500 ((A1 · A2). (A3 . A4))
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.