SlideShare a Scribd company logo
1 of 27
Respa Peter
Roll No:12
 What is Dynamic Programming?
 Matrix-Chain Multiplication
 Dynamic Programming is a technique for algorithm design.
 It is a tabular method in which it uses divide-and-conquer
to solve problems.
 dynamic programming is applicable when the subproblems
are not independent.
 So to solve a given problem, we need to solve different
parts of the problem.
 A dynamic programming approach consists
of a sequence of 4 steps
1. Characterize the structure of an optimal solution
2. Recursively define the value of an optimal solution
3. Compute the value of an optimal solution in a
bottom-up fashion
4. Construct an optimal solution from computed
information
Input: a chain of matrices to be multiplied
Output: a parenthesizing of the chain
Objective: minimize number of steps
needed for the multiplication
 Suppose we have a sequence or chain A1, A2, …, An of n
matrices to be multiplied
That is, we want to compute the product A1A2…An
 There are many possible ways (parenthesizations) to
compute the product
 Example: consider the chain A1, A2, A3, A4 of 4
matrices
◦ Let us compute the product A1A2A3A4
• 5 different orderings = 5 different parenthesizations
1. (A1(A2(A3A4)))
2. (A1((A2A3)A4))
3. ((A1A2)(A3A4))
4. ((A1(A2A3))A4)
5. (((A1A2)A3)A4)
• Matrix multiplication is associative ,
e.g.,
so parenthenization does not
change result.
• To compute the number of scalar
multiplications necessary, we must know:
• Algorithm to multiply two matrices
• Matrix dimensions
Algorithm..
Matrix-Multiply(A,B)
1.If columns[A]!=rows[B]
2. then error “incomplete dimensions”
3. else for i 1 to rows[A]
4. do for j 1 to columns[B]
5. do C[i,j] 0
6. for k 1 to columns[A]
7. Do C[i,j]=C[i,j]+A[i,k]*B[k,j]
8. Return C
•The time to compute C is dominated by the
number of scalar multiplications.
•To illustrate the different costs incurred by
different paranthesization of a matrix product.
Example: Consider three matrices A10100, B1005, and C550 There are 2 ways to
parenthesize
((AB)C) = D105 · C550
AB  10·100·5=5,000 scalar multiplications
DC  10·5·50 =2,500 scalar multiplications
(A(BC)) = A10100 · E10050
BC  100·5·50=25,000 scalar multiplications Total: 75,000
AE  10·100·50 =50,000 scalar multiplications
Total:
7,500
• Matrix-chain multiplication problem
 Given a chain A1, A2, …, An of n
matrices, where for i=1, 2, …, n, matrix
Ai has dimension pi-1pi
 Parenthesize the product A1A2…An such
that the total number of scalar
multiplications is minimized
• Before solving by Dynamic programming
exhaustively check all paranthesizations.
• P(n) : paranthesization of a sequence of
n matrices
Counting the Number of Parenthesizations
•We obtain the recurrence
P n
if n
P k p n k if n
k
n( )
( ) ( )


 






1 1
2
1
1
1.The Structure of an Optimal Parenthesization
Step 1: Characterize the structure of an optimal solution
•Ai..j : matrix that results from evaluating the product Ai Ai+1 Ai+2 ... Aj
•An optimal parenthesization of the product A1A2 ... An
– Splits the product between Ak and Ak+1, for some 1≤k<n
(A1A2A3 ... Ak) · (Ak+1Ak+2 ... An)
– i.e., first compute A1..k and Ak+1..n and then multiply these two
• The cost of this optimal parenthesization
Cost of computing A1..k
+ Cost of computing Ak+1..n
+ Cost of multiplying A1..k · Ak+1..n
Optimal (sub)structure:
• Suppose that optimal parenthesization of Ai;j splits between Ak and Ak+1.
• Then, parenthesizations of Ai;k and Ak+1;j must be optimal, too
(otherwise, enhance overall solution — subproblems are independent!).
Construct optimal solution:
1. split into subproblems (using optimal split!),
2. parenthesize them optimally,
3. combine optimal subproblem solutions.
2. Recursively def. value of opt. solution
•Let m[i; j] denote minimum number of scalar multiplications needed to
compute Ai;j = Ai*Ai+1….Aj (full problem: m[1; n]).
Recursive definition of m[i; j]:
• if i = j, then
m[i; j] = m[i; i] = 0
(Ai;i = Ai, no mult. needed).
•We also keep track of optimal splits:
4.Computing the Optimal Cost
Computing the Optimal Cost(cont..)
Algorithm for Computing the
Optimal Costs
Example:
656
545
434
323
212
101
2520
2010
105
515
1535
3530
ppA
ppA
ppA
ppA
ppA
ppA






The m and s table computed by MATRIX-
CHAIN-ORDER for n=6
m[2,5]=
min{
m[2,2]+m[3,5]+p1p2p5=0+2500+351520
=13000,
m[2,3]+m[4,5]+p1p3p5=2625+1000+355
20=7125,
m[2,4]+m[5,5]+p1p4p5=4375+0+351020
=11374
}
=7125
4.Constructing an Optimal
Solution
Matrix chain multiplication
Matrix chain multiplication

More Related Content

What's hot

Longest Common Subsequence
Longest Common SubsequenceLongest Common Subsequence
Longest Common SubsequenceKrishma Parekh
 
strassen matrix multiplication algorithm
strassen matrix multiplication algorithmstrassen matrix multiplication algorithm
strassen matrix multiplication algorithmevil eye
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notationsNikhil Sharma
 
BackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and ExamplesBackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and ExamplesFahim Ferdous
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy methodhodcsencet
 
Algorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms IAlgorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms IMohamed Loey
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of AlgorithmsSwapnil Agrawal
 
Prims and kruskal algorithms
Prims and kruskal algorithmsPrims and kruskal algorithms
Prims and kruskal algorithmsSaga Valsalan
 
finding Min and max element from given array using divide & conquer
finding Min and max element from given array using  divide & conquer finding Min and max element from given array using  divide & conquer
finding Min and max element from given array using divide & conquer Swati Kulkarni Jaipurkar
 
Matrix chain multiplication by MHM
Matrix chain multiplication by MHMMatrix chain multiplication by MHM
Matrix chain multiplication by MHMMd Mosharof Hosen
 
Design and analysis of algorithms
Design and analysis of algorithmsDesign and analysis of algorithms
Design and analysis of algorithmsDr Geetha Mohan
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic NotationsRishabh Soni
 
Amortized Analysis of Algorithms
Amortized Analysis of Algorithms Amortized Analysis of Algorithms
Amortized Analysis of Algorithms sathish sak
 

What's hot (20)

Longest Common Subsequence
Longest Common SubsequenceLongest Common Subsequence
Longest Common Subsequence
 
chapter 1
chapter 1chapter 1
chapter 1
 
strassen matrix multiplication algorithm
strassen matrix multiplication algorithmstrassen matrix multiplication algorithm
strassen matrix multiplication algorithm
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
BackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and ExamplesBackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and Examples
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy method
 
Algorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms IAlgorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms I
 
Np cooks theorem
Np cooks theoremNp cooks theorem
Np cooks theorem
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of Algorithms
 
Context free grammar
Context free grammarContext free grammar
Context free grammar
 
Randomized algorithms ver 1.0
Randomized algorithms ver 1.0Randomized algorithms ver 1.0
Randomized algorithms ver 1.0
 
Prims and kruskal algorithms
Prims and kruskal algorithmsPrims and kruskal algorithms
Prims and kruskal algorithms
 
finding Min and max element from given array using divide & conquer
finding Min and max element from given array using  divide & conquer finding Min and max element from given array using  divide & conquer
finding Min and max element from given array using divide & conquer
 
Matrix chain multiplication by MHM
Matrix chain multiplication by MHMMatrix chain multiplication by MHM
Matrix chain multiplication by MHM
 
Design and analysis of algorithms
Design and analysis of algorithmsDesign and analysis of algorithms
Design and analysis of algorithms
 
Context free grammar
Context free grammar Context free grammar
Context free grammar
 
Minimum spanning tree
Minimum spanning treeMinimum spanning tree
Minimum spanning tree
 
Lexical analysis - Compiler Design
Lexical analysis - Compiler DesignLexical analysis - Compiler Design
Lexical analysis - Compiler Design
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
 
Amortized Analysis of Algorithms
Amortized Analysis of Algorithms Amortized Analysis of Algorithms
Amortized Analysis of Algorithms
 

Similar to Matrix chain multiplication

Matrix multiplicationdesign
Matrix multiplicationdesignMatrix multiplicationdesign
Matrix multiplicationdesignRespa Peter
 
Computer algorithm(Dynamic Programming).pdf
Computer algorithm(Dynamic Programming).pdfComputer algorithm(Dynamic Programming).pdf
Computer algorithm(Dynamic Programming).pdfjannatulferdousmaish
 
Matrix chain multiplication in design analysis of algorithm
Matrix chain multiplication in design analysis of algorithmMatrix chain multiplication in design analysis of algorithm
Matrix chain multiplication in design analysis of algorithmRajKumar323561
 
Matrix mult class-17
Matrix mult class-17Matrix mult class-17
Matrix mult class-17Kumar
 
Dynamic programming1
Dynamic programming1Dynamic programming1
Dynamic programming1debolina13
 
Lecture -16-merge sort (slides).pptx
Lecture -16-merge sort (slides).pptxLecture -16-merge sort (slides).pptx
Lecture -16-merge sort (slides).pptxFazlullah28
 
Chapter 5.pptx
Chapter 5.pptxChapter 5.pptx
Chapter 5.pptxTekle12
 
DAA - chapter 1.pdf
DAA - chapter 1.pdfDAA - chapter 1.pdf
DAA - chapter 1.pdfASMAALWADEE2
 
MATLAB sessions Laboratory 2MAT 275 Laboratory 2Matrix .docx
MATLAB sessions Laboratory 2MAT 275 Laboratory 2Matrix .docxMATLAB sessions Laboratory 2MAT 275 Laboratory 2Matrix .docx
MATLAB sessions Laboratory 2MAT 275 Laboratory 2Matrix .docxandreecapon
 
Dynamic1
Dynamic1Dynamic1
Dynamic1MyAlome
 
Intro matlab and convolution islam
Intro matlab and convolution islamIntro matlab and convolution islam
Intro matlab and convolution islamIslam Alabbasy
 
matrix algebra
matrix algebramatrix algebra
matrix algebrakganu
 

Similar to Matrix chain multiplication (20)

Matrix multiplicationdesign
Matrix multiplicationdesignMatrix multiplicationdesign
Matrix multiplicationdesign
 
Computer algorithm(Dynamic Programming).pdf
Computer algorithm(Dynamic Programming).pdfComputer algorithm(Dynamic Programming).pdf
Computer algorithm(Dynamic Programming).pdf
 
Matrix chain multiplication in design analysis of algorithm
Matrix chain multiplication in design analysis of algorithmMatrix chain multiplication in design analysis of algorithm
Matrix chain multiplication in design analysis of algorithm
 
Matrix mult class-17
Matrix mult class-17Matrix mult class-17
Matrix mult class-17
 
Dynamic programming1
Dynamic programming1Dynamic programming1
Dynamic programming1
 
Daa chapter 3
Daa chapter 3Daa chapter 3
Daa chapter 3
 
Lecture -16-merge sort (slides).pptx
Lecture -16-merge sort (slides).pptxLecture -16-merge sort (slides).pptx
Lecture -16-merge sort (slides).pptx
 
Chapter 5.pptx
Chapter 5.pptxChapter 5.pptx
Chapter 5.pptx
 
matrices basic operation.ppt
matrices basic operation.pptmatrices basic operation.ppt
matrices basic operation.ppt
 
DAA - chapter 1.pdf
DAA - chapter 1.pdfDAA - chapter 1.pdf
DAA - chapter 1.pdf
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
 
MATLAB sessions Laboratory 2MAT 275 Laboratory 2Matrix .docx
MATLAB sessions Laboratory 2MAT 275 Laboratory 2Matrix .docxMATLAB sessions Laboratory 2MAT 275 Laboratory 2Matrix .docx
MATLAB sessions Laboratory 2MAT 275 Laboratory 2Matrix .docx
 
Assignment On Matlab
Assignment On MatlabAssignment On Matlab
Assignment On Matlab
 
Dynamic1
Dynamic1Dynamic1
Dynamic1
 
Mechanical Engineering Homework Help
Mechanical Engineering Homework HelpMechanical Engineering Homework Help
Mechanical Engineering Homework Help
 
Lecture 7.pptx
Lecture 7.pptxLecture 7.pptx
Lecture 7.pptx
 
Lesson 1 matrix
Lesson 1 matrixLesson 1 matrix
Lesson 1 matrix
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 
Intro matlab and convolution islam
Intro matlab and convolution islamIntro matlab and convolution islam
Intro matlab and convolution islam
 
matrix algebra
matrix algebramatrix algebra
matrix algebra
 

More from Respa Peter

Tpes of Softwares
Tpes of SoftwaresTpes of Softwares
Tpes of SoftwaresRespa Peter
 
Information technology for business
Information technology for business Information technology for business
Information technology for business Respa Peter
 
Types of sql injection attacks
Types of sql injection attacksTypes of sql injection attacks
Types of sql injection attacksRespa Peter
 
DataMining Techniq
DataMining TechniqDataMining Techniq
DataMining TechniqRespa Peter
 
software failures
 software failures software failures
software failuresRespa Peter
 
Managing software development
Managing software developmentManaging software development
Managing software developmentRespa Peter
 
Genetic algorithm
Genetic algorithmGenetic algorithm
Genetic algorithmRespa Peter
 
Web services have made the development of mobile Web applications much easier...
Web services have made the development of mobile Web applications much easier...Web services have made the development of mobile Web applications much easier...
Web services have made the development of mobile Web applications much easier...Respa Peter
 
Open shortest path first (ospf)
Open shortest path first (ospf)Open shortest path first (ospf)
Open shortest path first (ospf)Respa Peter
 

More from Respa Peter (13)

Tpes of Softwares
Tpes of SoftwaresTpes of Softwares
Tpes of Softwares
 
Information technology for business
Information technology for business Information technology for business
Information technology for business
 
Types of sql injection attacks
Types of sql injection attacksTypes of sql injection attacks
Types of sql injection attacks
 
DataMining Techniq
DataMining TechniqDataMining Techniq
DataMining Techniq
 
Database
DatabaseDatabase
Database
 
software failures
 software failures software failures
software failures
 
Cloud computing
Cloud computingCloud computing
Cloud computing
 
Managing software development
Managing software developmentManaging software development
Managing software development
 
Data mining
Data miningData mining
Data mining
 
Knime
KnimeKnime
Knime
 
Genetic algorithm
Genetic algorithmGenetic algorithm
Genetic algorithm
 
Web services have made the development of mobile Web applications much easier...
Web services have made the development of mobile Web applications much easier...Web services have made the development of mobile Web applications much easier...
Web services have made the development of mobile Web applications much easier...
 
Open shortest path first (ospf)
Open shortest path first (ospf)Open shortest path first (ospf)
Open shortest path first (ospf)
 

Recently uploaded

UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 

Recently uploaded (20)

UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 

Matrix chain multiplication

  • 2.  What is Dynamic Programming?  Matrix-Chain Multiplication
  • 3.  Dynamic Programming is a technique for algorithm design.  It is a tabular method in which it uses divide-and-conquer to solve problems.  dynamic programming is applicable when the subproblems are not independent.  So to solve a given problem, we need to solve different parts of the problem.
  • 4.  A dynamic programming approach consists of a sequence of 4 steps 1. Characterize the structure of an optimal solution 2. Recursively define the value of an optimal solution 3. Compute the value of an optimal solution in a bottom-up fashion 4. Construct an optimal solution from computed information
  • 5.
  • 6. Input: a chain of matrices to be multiplied Output: a parenthesizing of the chain Objective: minimize number of steps needed for the multiplication
  • 7.  Suppose we have a sequence or chain A1, A2, …, An of n matrices to be multiplied That is, we want to compute the product A1A2…An  There are many possible ways (parenthesizations) to compute the product
  • 8.  Example: consider the chain A1, A2, A3, A4 of 4 matrices ◦ Let us compute the product A1A2A3A4 • 5 different orderings = 5 different parenthesizations 1. (A1(A2(A3A4))) 2. (A1((A2A3)A4)) 3. ((A1A2)(A3A4)) 4. ((A1(A2A3))A4) 5. (((A1A2)A3)A4)
  • 9. • Matrix multiplication is associative , e.g., so parenthenization does not change result. • To compute the number of scalar multiplications necessary, we must know: • Algorithm to multiply two matrices • Matrix dimensions
  • 10. Algorithm.. Matrix-Multiply(A,B) 1.If columns[A]!=rows[B] 2. then error “incomplete dimensions” 3. else for i 1 to rows[A] 4. do for j 1 to columns[B] 5. do C[i,j] 0 6. for k 1 to columns[A] 7. Do C[i,j]=C[i,j]+A[i,k]*B[k,j] 8. Return C
  • 11. •The time to compute C is dominated by the number of scalar multiplications. •To illustrate the different costs incurred by different paranthesization of a matrix product. Example: Consider three matrices A10100, B1005, and C550 There are 2 ways to parenthesize ((AB)C) = D105 · C550 AB  10·100·5=5,000 scalar multiplications DC  10·5·50 =2,500 scalar multiplications (A(BC)) = A10100 · E10050 BC  100·5·50=25,000 scalar multiplications Total: 75,000 AE  10·100·50 =50,000 scalar multiplications Total: 7,500
  • 12. • Matrix-chain multiplication problem  Given a chain A1, A2, …, An of n matrices, where for i=1, 2, …, n, matrix Ai has dimension pi-1pi  Parenthesize the product A1A2…An such that the total number of scalar multiplications is minimized
  • 13. • Before solving by Dynamic programming exhaustively check all paranthesizations. • P(n) : paranthesization of a sequence of n matrices Counting the Number of Parenthesizations
  • 14. •We obtain the recurrence P n if n P k p n k if n k n( ) ( ) ( )           1 1 2 1 1
  • 15. 1.The Structure of an Optimal Parenthesization Step 1: Characterize the structure of an optimal solution •Ai..j : matrix that results from evaluating the product Ai Ai+1 Ai+2 ... Aj •An optimal parenthesization of the product A1A2 ... An – Splits the product between Ak and Ak+1, for some 1≤k<n (A1A2A3 ... Ak) · (Ak+1Ak+2 ... An) – i.e., first compute A1..k and Ak+1..n and then multiply these two • The cost of this optimal parenthesization Cost of computing A1..k + Cost of computing Ak+1..n + Cost of multiplying A1..k · Ak+1..n
  • 16. Optimal (sub)structure: • Suppose that optimal parenthesization of Ai;j splits between Ak and Ak+1. • Then, parenthesizations of Ai;k and Ak+1;j must be optimal, too (otherwise, enhance overall solution — subproblems are independent!). Construct optimal solution: 1. split into subproblems (using optimal split!), 2. parenthesize them optimally, 3. combine optimal subproblem solutions.
  • 17. 2. Recursively def. value of opt. solution •Let m[i; j] denote minimum number of scalar multiplications needed to compute Ai;j = Ai*Ai+1….Aj (full problem: m[1; n]). Recursive definition of m[i; j]: • if i = j, then m[i; j] = m[i; i] = 0 (Ai;i = Ai, no mult. needed).
  • 18. •We also keep track of optimal splits:
  • 20. Computing the Optimal Cost(cont..)
  • 21. Algorithm for Computing the Optimal Costs
  • 23. The m and s table computed by MATRIX- CHAIN-ORDER for n=6