SlideShare a Scribd company logo
1 of 20
Dynamic Programming
Lecture:17 DEBOLINA PAN
Date: 01.10.13 I.D-110811026
1. Dynamic Programming
2. Comparison with divide n concuer
3. Where used?
4. Matrix Multiplication
5. Algo to multiply 2 matrices
6. #scaler multiplication used in matrix multiplication
7. Costs &parenthisization
8. Matrix multiplication Problem
9. Counting the #parenthisization
10. Brute force Method
11. Computing optimal cost
12. Matrix chain Order
13. Overlapping Subproblem
14. Memorization
 dynamic programming is a method for
solving complex problems by breaking them
down into simpler subproblems.and the
subproblems are dependent.
 programming is an expression of algorithm.i
dynamic programing the languag,used does
not refer to any computer language,rather it
refers to formal language.
 Dynamic programming, like the divide-and-conquer method,
solves problems by combining the solutions to subproblems.
 divide-and-conquer algorithms partition the problem into
disjoint subproblems, solve the subproblems recursively, and
then combine their solutions to solve the original problem. In
contrast, dynamic programming applies when the subproblems
overlap—that is, when subproblems share subsubproblems.
 a divide-and-conquer algorithm does more work than necessary,
repeatedly solving the common subsubproblems. A dynamic-
programming algorithm solves each subsubproblem just once
and then saves its answer in a table, thereby avoiding the work
of recomputing the answer every time it solves each
subsubproblem
 We typically apply dynamic programming to
optimization problems.
 Such problems can have many possible
solutions. Each solution has a value, and we
wish to find a solution with the optimal
(minimum or maximum) value. We call such a
solution an optimal solution to the problem,
as opposed to the optimal solution, since
there may be several solutions that achieve
the optimal value.
 Say,there are 2 matrices A & B.
 We can multiply 2 matrices only if they are
compatible.
 Condition to be multiplied:#collumns of A
=#rows of B.
 If the resultant matrix is C,then
Am*n * B n*p= Cm*p
MATRIX-MULTIPLY(A,B)
1 .if columns[A] ≠rows[B]
2 . Then error “incompatible dimensions”
3 . let C be a new A:rows B:columns matrix
4 .for i <-1 to A.rows
5 .for j<-1 to B.columns
6 .cij =0
7 .for k =1 to A.columns
8 .cij =cij + aik .bkj
9 .return C
 In the above example of matrix multiplication
if we consider,
 m=2,n=3,p=4,the total number of scaler
multiplication used is 24,i.e m*n*p.
 We shall express costs in terms of the
number of scaler multiplications.
 Example:
A1->10*100
A2->100*5
A3->5*50
If(A1*A2)*A3=>#scaler multiplication:
(10*100*5) + (10*5*50)=7500
IfA1*(A2*A3)=>#scaler multiplication:
(10*100*50)+(100*5*50)=75000
=>Ordering of parenthasization is important.
 matrix-chain multiplication problem can be
stated as follows: given a chain
<A1,A2,…,An> of n matrices, where for
i=1,2, …,n, matrix Ai has dimension pi-1*pi ,
fully parenthesize the product A1A2…An in a
way that minimizes the number of scalar
multiplications.
 Our goal is only to determine an order for
multiplying matrices that has the lowest cost.
 P(n) is the number of alternative
parenthesizations of a sequence of n
matrices.
 When n=1,P(n)=1,as there is only 1 matrix,so
only one way to put parenthesis.
 n=2,P(n)=1,only one way to put parenthesis.
 n=3,P(n)=2, (A1*A2)*A3 & A1*(A2*A3)
 N=4,P(n)=6
 (((A1*A2)*A3)*A4) (A1*((A2*A3)*A4)
 ((A1*A2)*(A3*A4)) (A1*(A2*(A3*A4)))
 (A1*(A2*A3))*A4 ((A1*A2)*(A3*A4))
 Thus we obtain the sequence:
◦ P(n)= 1 if n=1
 ∑k=1to n-1 P(k)P(n-k) if n≥2 a fully
parenthasize matrix product is a
prodct of 2 fully parenthasize matrix
sbproducts.split between two
sbprducts may occr between the k th
& k+1 th matrix for any k=1…n-1
Rate of growth: Ω((4^n)/(n^(3/2)))
 general problem-solving technique that
consists of systematically enumerating all
possible candidates for the solution and
checking whether each candidate satisfies the
problem's statement.
 Lower bound of this problem using brute
force method is Ω((4^n)/(n^(3/2)))
 That means brute force method as the solution of
the problem is not so good.
 At this point, we could easily write a recursive
algorithm based on recurrence to compute the
minimum cost m[1,n]for multiplying A1,A2,…, An.
Aswe sawfor the rod-cutting problem, and this
recursive algorithm takes exponential time, which is
no better than the brute-force method of checking
each way of parenthesizing the product.
 we have relatively few distinct subproblems: one
subproblem for each choice of i and j satisfying 1 ≤i≤
j≤n, or (nc2 +n)=Θ(n^2) in all. A recursive algorithm
may encounter each subproblem many times in
different branches of its recursion tree. This property
of overlapping subproblems is the second hallmark of
when dynamic programming applies.
 Instead of computing the solution to recurrence
recursively, we compute the optimal cost by using a
tabular, bottom-up approach.
 We shall implement the tabular, bottom-up method
in the procedure MATRIXCHAIN-ORDER, which
appears below. This procedure assumes that matrix
Ai has dimensions pi-1 *pi for i=1,2,…,n. Its input is
a sequence p=<p0; p1; : : : ;pni> where length[p] =
n+1. The procedure uses an auxiliary table
m[1…n,1…n] for storing the m[I,j] costs and another
auxiliary table s[1…n,1…n]that records which index
of k achieved the optimal cost in computing m[i; j
].We shall use the table s to construct an optimal
solution.
 In order to implement the bottom-up approach, we
must determine which entries of the table we refer to
when computing m[i,j].the cost m[i ,j] of computing a
matrix-chain product of j-i+1matrices depends only
on the costs of computing matrix-chain products of
fewer than j-i+1 matrices. That is, for k =I,i +1,…,j-
1, the matrix Ai…k is a product of k-i+1< j-i+1
matrices and the matrix Ak+1…j is a product of j-k<
j-i +1 matrices. Thus, the algorithm should fill in the
table min a manner that corresponds to solving the
parenthesization problem on matrix chains of
increasing length. For the subproblem of optimally
parenthesizing the chain Ai,Ai+1,… Aj,we consider
the subproblem size to be the length j-i+1 of the
chain.
MATRIX-CHAIN-ORDER.p/
1. n D p:length 1
2.Let m[1,… n.1,… n] and s[1,… n-1. 2…n] be new tables
3. for i =1 to n
4.Do m[i,j] <-0
5. for l =2 to n // l is the chain length
6. dofor i =1 to n –l+1
7. Do j<-i+l-1
8. m[i, j]<- infinity
9.for k <-i to j-1
10. Do q <-m[i, k]+m[k+1,j]+pi-1.pk.pj
11. if q <m[i,j]
12. m[i, j]<-q
13. s[i,j]<-k
14. return m and s
 running time of this algorithm is in fact also
Ω(n^3) The algorithm requiresΘ(n^2) space
to store the m and s tables. Thus, MATRIX-
CHAINORDER is much more efficient than the
exponential-time method of enumerating all
possible parenthesizations and checking each
one
 In dynamic problem
subproblems are
dependent.
 Dynamic-programming
algorithms typically take
advantage of overlapping
subproblems by solving
each subproblem once and
then storing the solution in
a table where it can be
looked up when needed,
using constant time per
lookup.
 Cost is reduced.
(A1 *A2) (A3*(A4*A5))
(A1*A2) (A3*A4)*A5
^
|
Overlapping
subproblem
 A memoized recursive algorithm maintains an
entry in a table for the solution to each
subproblem. Each table entry initially
contains a special value to indicate that the
entry has yet to be filled in. When the
subproblem is first encountered as the
recursive algorithm unfolds, its solution is
computed and then stored in the table. Each
subsequent time that we encounter this
subproblem, we simply look up the value
stored in the table and return it

More Related Content

What's hot

Dynamic programming - fundamentals review
Dynamic programming - fundamentals reviewDynamic programming - fundamentals review
Dynamic programming - fundamentals reviewElifTech
 
Dynamic programming in Algorithm Analysis
Dynamic programming in Algorithm AnalysisDynamic programming in Algorithm Analysis
Dynamic programming in Algorithm AnalysisRajendran
 
Dynamic Programming - Matrix Chain Multiplication
Dynamic Programming - Matrix Chain MultiplicationDynamic Programming - Matrix Chain Multiplication
Dynamic Programming - Matrix Chain MultiplicationPecha Inc.
 
Dynamic Programming
Dynamic ProgrammingDynamic Programming
Dynamic ProgrammingSahil Kumar
 
Dynamic Programming - Part 1
Dynamic Programming - Part 1Dynamic Programming - Part 1
Dynamic Programming - Part 1Amrinder Arora
 
Daa:Dynamic Programing
Daa:Dynamic ProgramingDaa:Dynamic Programing
Daa:Dynamic Programingrupali_2bonde
 
Lecture 8 dynamic programming
Lecture 8 dynamic programmingLecture 8 dynamic programming
Lecture 8 dynamic programmingOye Tu
 
dynamic programming complete by Mumtaz Ali (03154103173)
dynamic programming complete by Mumtaz Ali (03154103173)dynamic programming complete by Mumtaz Ali (03154103173)
dynamic programming complete by Mumtaz Ali (03154103173)Mumtaz Ali
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programmingJay Nagar
 
Matrix multiplicationdesign
Matrix multiplicationdesignMatrix multiplicationdesign
Matrix multiplicationdesignRespa Peter
 
Skiena algorithm 2007 lecture16 introduction to dynamic programming
Skiena algorithm 2007 lecture16 introduction to dynamic programmingSkiena algorithm 2007 lecture16 introduction to dynamic programming
Skiena algorithm 2007 lecture16 introduction to dynamic programmingzukun
 
Dynamic programming (dp) in Algorithm
Dynamic programming (dp) in AlgorithmDynamic programming (dp) in Algorithm
Dynamic programming (dp) in AlgorithmRaihanIslamSonet
 
Dynamic Programming - Part II
Dynamic Programming - Part IIDynamic Programming - Part II
Dynamic Programming - Part IIAmrinder Arora
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy methodhodcsencet
 

What's hot (20)

Dynamic programming - fundamentals review
Dynamic programming - fundamentals reviewDynamic programming - fundamentals review
Dynamic programming - fundamentals review
 
Dynamic programming in Algorithm Analysis
Dynamic programming in Algorithm AnalysisDynamic programming in Algorithm Analysis
Dynamic programming in Algorithm Analysis
 
Dynamic Programming - Matrix Chain Multiplication
Dynamic Programming - Matrix Chain MultiplicationDynamic Programming - Matrix Chain Multiplication
Dynamic Programming - Matrix Chain Multiplication
 
Dynamic Programming
Dynamic ProgrammingDynamic Programming
Dynamic Programming
 
Dynamic Programming - Part 1
Dynamic Programming - Part 1Dynamic Programming - Part 1
Dynamic Programming - Part 1
 
Daa:Dynamic Programing
Daa:Dynamic ProgramingDaa:Dynamic Programing
Daa:Dynamic Programing
 
Lecture 8 dynamic programming
Lecture 8 dynamic programmingLecture 8 dynamic programming
Lecture 8 dynamic programming
 
dynamic programming complete by Mumtaz Ali (03154103173)
dynamic programming complete by Mumtaz Ali (03154103173)dynamic programming complete by Mumtaz Ali (03154103173)
dynamic programming complete by Mumtaz Ali (03154103173)
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 
Matrix multiplicationdesign
Matrix multiplicationdesignMatrix multiplicationdesign
Matrix multiplicationdesign
 
Skiena algorithm 2007 lecture16 introduction to dynamic programming
Skiena algorithm 2007 lecture16 introduction to dynamic programmingSkiena algorithm 2007 lecture16 introduction to dynamic programming
Skiena algorithm 2007 lecture16 introduction to dynamic programming
 
Dynamic programming (dp) in Algorithm
Dynamic programming (dp) in AlgorithmDynamic programming (dp) in Algorithm
Dynamic programming (dp) in Algorithm
 
Dynamic programming Basics
Dynamic programming BasicsDynamic programming Basics
Dynamic programming Basics
 
Dynamic Programming - Part II
Dynamic Programming - Part IIDynamic Programming - Part II
Dynamic Programming - Part II
 
Greedy Algorithms
Greedy AlgorithmsGreedy Algorithms
Greedy Algorithms
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 
DS ppt
DS pptDS ppt
DS ppt
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy method
 

Viewers also liked

Dynamic Program Problems
Dynamic Program ProblemsDynamic Program Problems
Dynamic Program ProblemsRanjit Sasmal
 
Dynamic programmng2
Dynamic programmng2Dynamic programmng2
Dynamic programmng2debolina13
 
Graph Traversal Algorithm
Graph Traversal AlgorithmGraph Traversal Algorithm
Graph Traversal Algorithmjyothimonc
 
Stressen's matrix multiplication
Stressen's matrix multiplicationStressen's matrix multiplication
Stressen's matrix multiplicationKumar
 
Minimum Spanning Tree
Minimum Spanning TreeMinimum Spanning Tree
Minimum Spanning Treezhaokatherine
 
strassen matrix multiplication algorithm
strassen matrix multiplication algorithmstrassen matrix multiplication algorithm
strassen matrix multiplication algorithmevil eye
 
Sec15 dynamic programming
Sec15 dynamic programmingSec15 dynamic programming
Sec15 dynamic programmingKeisuke OTAKI
 

Viewers also liked (10)

Dynamic Program Problems
Dynamic Program ProblemsDynamic Program Problems
Dynamic Program Problems
 
Android
AndroidAndroid
Android
 
Dynamic programmng2
Dynamic programmng2Dynamic programmng2
Dynamic programmng2
 
Hashing
HashingHashing
Hashing
 
Graph Traversal Algorithm
Graph Traversal AlgorithmGraph Traversal Algorithm
Graph Traversal Algorithm
 
Stressen's matrix multiplication
Stressen's matrix multiplicationStressen's matrix multiplication
Stressen's matrix multiplication
 
Minimum spanning tree
Minimum spanning treeMinimum spanning tree
Minimum spanning tree
 
Minimum Spanning Tree
Minimum Spanning TreeMinimum Spanning Tree
Minimum Spanning Tree
 
strassen matrix multiplication algorithm
strassen matrix multiplication algorithmstrassen matrix multiplication algorithm
strassen matrix multiplication algorithm
 
Sec15 dynamic programming
Sec15 dynamic programmingSec15 dynamic programming
Sec15 dynamic programming
 

Similar to Dynamic programming1

Computer algorithm(Dynamic Programming).pdf
Computer algorithm(Dynamic Programming).pdfComputer algorithm(Dynamic Programming).pdf
Computer algorithm(Dynamic Programming).pdfjannatulferdousmaish
 
DAA - UNIT 4 - Engineering.pptx
DAA - UNIT 4 - Engineering.pptxDAA - UNIT 4 - Engineering.pptx
DAA - UNIT 4 - Engineering.pptxvaishnavi339314
 
Dynamic1
Dynamic1Dynamic1
Dynamic1MyAlome
 
Matrix Multiplication(An example of concurrent programming)
Matrix Multiplication(An example of concurrent programming)Matrix Multiplication(An example of concurrent programming)
Matrix Multiplication(An example of concurrent programming)Pramit Kumar
 
9 - DynamicProgramming-plus latihan.ppt
9 - DynamicProgramming-plus latihan.ppt9 - DynamicProgramming-plus latihan.ppt
9 - DynamicProgramming-plus latihan.pptKerbauBakar
 
Chapter 5.pptx
Chapter 5.pptxChapter 5.pptx
Chapter 5.pptxTekle12
 
adminSticky Note- the process of inversion is shown in .docx
adminSticky Note- the process of inversion is shown in  .docxadminSticky Note- the process of inversion is shown in  .docx
adminSticky Note- the process of inversion is shown in .docxbobbywlane695641
 
adminSticky Note- the process of inversion is shown in .docx
adminSticky Note- the process of inversion is shown in  .docxadminSticky Note- the process of inversion is shown in  .docx
adminSticky Note- the process of inversion is shown in .docxgalerussel59292
 
Matlab intro notes
Matlab intro notesMatlab intro notes
Matlab intro notespawanss
 
Investigación de operaciones 026 programación lineal Solución Simplex con R S...
Investigación de operaciones 026 programación lineal Solución Simplex con R S...Investigación de operaciones 026 programación lineal Solución Simplex con R S...
Investigación de operaciones 026 programación lineal Solución Simplex con R S...Jorge Pablo Rivas
 
tw1979 Exercise 1 Report
tw1979 Exercise 1 Reporttw1979 Exercise 1 Report
tw1979 Exercise 1 ReportThomas Wigg
 
Cs6402 design and analysis of algorithms may june 2016 answer key
Cs6402 design and analysis of algorithms may june 2016 answer keyCs6402 design and analysis of algorithms may june 2016 answer key
Cs6402 design and analysis of algorithms may june 2016 answer keyappasami
 

Similar to Dynamic programming1 (20)

Computer algorithm(Dynamic Programming).pdf
Computer algorithm(Dynamic Programming).pdfComputer algorithm(Dynamic Programming).pdf
Computer algorithm(Dynamic Programming).pdf
 
Daa chapter 3
Daa chapter 3Daa chapter 3
Daa chapter 3
 
Chapter 16
Chapter 16Chapter 16
Chapter 16
 
DAA - UNIT 4 - Engineering.pptx
DAA - UNIT 4 - Engineering.pptxDAA - UNIT 4 - Engineering.pptx
DAA - UNIT 4 - Engineering.pptx
 
Dynamic1
Dynamic1Dynamic1
Dynamic1
 
Analysis of Algorithm
Analysis of AlgorithmAnalysis of Algorithm
Analysis of Algorithm
 
Exhaustive Combinatorial Enumeration
Exhaustive Combinatorial EnumerationExhaustive Combinatorial Enumeration
Exhaustive Combinatorial Enumeration
 
Matrix Multiplication(An example of concurrent programming)
Matrix Multiplication(An example of concurrent programming)Matrix Multiplication(An example of concurrent programming)
Matrix Multiplication(An example of concurrent programming)
 
9 - DynamicProgramming-plus latihan.ppt
9 - DynamicProgramming-plus latihan.ppt9 - DynamicProgramming-plus latihan.ppt
9 - DynamicProgramming-plus latihan.ppt
 
algorithm Unit 2
algorithm Unit 2 algorithm Unit 2
algorithm Unit 2
 
Unit 2 in daa
Unit 2 in daaUnit 2 in daa
Unit 2 in daa
 
Chapter 5.pptx
Chapter 5.pptxChapter 5.pptx
Chapter 5.pptx
 
Daa chapter11
Daa chapter11Daa chapter11
Daa chapter11
 
adminSticky Note- the process of inversion is shown in .docx
adminSticky Note- the process of inversion is shown in  .docxadminSticky Note- the process of inversion is shown in  .docx
adminSticky Note- the process of inversion is shown in .docx
 
adminSticky Note- the process of inversion is shown in .docx
adminSticky Note- the process of inversion is shown in  .docxadminSticky Note- the process of inversion is shown in  .docx
adminSticky Note- the process of inversion is shown in .docx
 
Matlab intro notes
Matlab intro notesMatlab intro notes
Matlab intro notes
 
Investigación de operaciones 026 programación lineal Solución Simplex con R S...
Investigación de operaciones 026 programación lineal Solución Simplex con R S...Investigación de operaciones 026 programación lineal Solución Simplex con R S...
Investigación de operaciones 026 programación lineal Solución Simplex con R S...
 
Daa chapter 2
Daa chapter 2Daa chapter 2
Daa chapter 2
 
tw1979 Exercise 1 Report
tw1979 Exercise 1 Reporttw1979 Exercise 1 Report
tw1979 Exercise 1 Report
 
Cs6402 design and analysis of algorithms may june 2016 answer key
Cs6402 design and analysis of algorithms may june 2016 answer keyCs6402 design and analysis of algorithms may june 2016 answer key
Cs6402 design and analysis of algorithms may june 2016 answer key
 

Recently uploaded

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
 
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
 
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
 
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
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
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
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGSIVASHANKAR N
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...ranjana rawat
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdfKamal Acharya
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
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
 
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
 
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
 
(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
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxfenichawla
 

Recently uploaded (20)

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...
 
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
 
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
 
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, ...
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
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
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
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
 
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
 
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
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
(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...
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 

Dynamic programming1

  • 1. Dynamic Programming Lecture:17 DEBOLINA PAN Date: 01.10.13 I.D-110811026
  • 2. 1. Dynamic Programming 2. Comparison with divide n concuer 3. Where used? 4. Matrix Multiplication 5. Algo to multiply 2 matrices 6. #scaler multiplication used in matrix multiplication 7. Costs &parenthisization 8. Matrix multiplication Problem 9. Counting the #parenthisization 10. Brute force Method 11. Computing optimal cost 12. Matrix chain Order 13. Overlapping Subproblem 14. Memorization
  • 3.  dynamic programming is a method for solving complex problems by breaking them down into simpler subproblems.and the subproblems are dependent.  programming is an expression of algorithm.i dynamic programing the languag,used does not refer to any computer language,rather it refers to formal language.
  • 4.  Dynamic programming, like the divide-and-conquer method, solves problems by combining the solutions to subproblems.  divide-and-conquer algorithms partition the problem into disjoint subproblems, solve the subproblems recursively, and then combine their solutions to solve the original problem. In contrast, dynamic programming applies when the subproblems overlap—that is, when subproblems share subsubproblems.  a divide-and-conquer algorithm does more work than necessary, repeatedly solving the common subsubproblems. A dynamic- programming algorithm solves each subsubproblem just once and then saves its answer in a table, thereby avoiding the work of recomputing the answer every time it solves each subsubproblem
  • 5.  We typically apply dynamic programming to optimization problems.  Such problems can have many possible solutions. Each solution has a value, and we wish to find a solution with the optimal (minimum or maximum) value. We call such a solution an optimal solution to the problem, as opposed to the optimal solution, since there may be several solutions that achieve the optimal value.
  • 6.  Say,there are 2 matrices A & B.  We can multiply 2 matrices only if they are compatible.  Condition to be multiplied:#collumns of A =#rows of B.  If the resultant matrix is C,then Am*n * B n*p= Cm*p
  • 7. MATRIX-MULTIPLY(A,B) 1 .if columns[A] ≠rows[B] 2 . Then error “incompatible dimensions” 3 . let C be a new A:rows B:columns matrix 4 .for i <-1 to A.rows 5 .for j<-1 to B.columns 6 .cij =0 7 .for k =1 to A.columns 8 .cij =cij + aik .bkj 9 .return C
  • 8.  In the above example of matrix multiplication if we consider,  m=2,n=3,p=4,the total number of scaler multiplication used is 24,i.e m*n*p.  We shall express costs in terms of the number of scaler multiplications.
  • 9.  Example: A1->10*100 A2->100*5 A3->5*50 If(A1*A2)*A3=>#scaler multiplication: (10*100*5) + (10*5*50)=7500 IfA1*(A2*A3)=>#scaler multiplication: (10*100*50)+(100*5*50)=75000 =>Ordering of parenthasization is important.
  • 10.  matrix-chain multiplication problem can be stated as follows: given a chain <A1,A2,…,An> of n matrices, where for i=1,2, …,n, matrix Ai has dimension pi-1*pi , fully parenthesize the product A1A2…An in a way that minimizes the number of scalar multiplications.  Our goal is only to determine an order for multiplying matrices that has the lowest cost.
  • 11.  P(n) is the number of alternative parenthesizations of a sequence of n matrices.  When n=1,P(n)=1,as there is only 1 matrix,so only one way to put parenthesis.  n=2,P(n)=1,only one way to put parenthesis.  n=3,P(n)=2, (A1*A2)*A3 & A1*(A2*A3)  N=4,P(n)=6  (((A1*A2)*A3)*A4) (A1*((A2*A3)*A4)  ((A1*A2)*(A3*A4)) (A1*(A2*(A3*A4)))  (A1*(A2*A3))*A4 ((A1*A2)*(A3*A4))
  • 12.  Thus we obtain the sequence: ◦ P(n)= 1 if n=1  ∑k=1to n-1 P(k)P(n-k) if n≥2 a fully parenthasize matrix product is a prodct of 2 fully parenthasize matrix sbproducts.split between two sbprducts may occr between the k th & k+1 th matrix for any k=1…n-1 Rate of growth: Ω((4^n)/(n^(3/2)))
  • 13.  general problem-solving technique that consists of systematically enumerating all possible candidates for the solution and checking whether each candidate satisfies the problem's statement.  Lower bound of this problem using brute force method is Ω((4^n)/(n^(3/2)))  That means brute force method as the solution of the problem is not so good.
  • 14.  At this point, we could easily write a recursive algorithm based on recurrence to compute the minimum cost m[1,n]for multiplying A1,A2,…, An. Aswe sawfor the rod-cutting problem, and this recursive algorithm takes exponential time, which is no better than the brute-force method of checking each way of parenthesizing the product.  we have relatively few distinct subproblems: one subproblem for each choice of i and j satisfying 1 ≤i≤ j≤n, or (nc2 +n)=Θ(n^2) in all. A recursive algorithm may encounter each subproblem many times in different branches of its recursion tree. This property of overlapping subproblems is the second hallmark of when dynamic programming applies.
  • 15.  Instead of computing the solution to recurrence recursively, we compute the optimal cost by using a tabular, bottom-up approach.  We shall implement the tabular, bottom-up method in the procedure MATRIXCHAIN-ORDER, which appears below. This procedure assumes that matrix Ai has dimensions pi-1 *pi for i=1,2,…,n. Its input is a sequence p=<p0; p1; : : : ;pni> where length[p] = n+1. The procedure uses an auxiliary table m[1…n,1…n] for storing the m[I,j] costs and another auxiliary table s[1…n,1…n]that records which index of k achieved the optimal cost in computing m[i; j ].We shall use the table s to construct an optimal solution.
  • 16.  In order to implement the bottom-up approach, we must determine which entries of the table we refer to when computing m[i,j].the cost m[i ,j] of computing a matrix-chain product of j-i+1matrices depends only on the costs of computing matrix-chain products of fewer than j-i+1 matrices. That is, for k =I,i +1,…,j- 1, the matrix Ai…k is a product of k-i+1< j-i+1 matrices and the matrix Ak+1…j is a product of j-k< j-i +1 matrices. Thus, the algorithm should fill in the table min a manner that corresponds to solving the parenthesization problem on matrix chains of increasing length. For the subproblem of optimally parenthesizing the chain Ai,Ai+1,… Aj,we consider the subproblem size to be the length j-i+1 of the chain.
  • 17. MATRIX-CHAIN-ORDER.p/ 1. n D p:length 1 2.Let m[1,… n.1,… n] and s[1,… n-1. 2…n] be new tables 3. for i =1 to n 4.Do m[i,j] <-0 5. for l =2 to n // l is the chain length 6. dofor i =1 to n –l+1 7. Do j<-i+l-1 8. m[i, j]<- infinity 9.for k <-i to j-1 10. Do q <-m[i, k]+m[k+1,j]+pi-1.pk.pj 11. if q <m[i,j] 12. m[i, j]<-q 13. s[i,j]<-k 14. return m and s
  • 18.  running time of this algorithm is in fact also Ω(n^3) The algorithm requiresΘ(n^2) space to store the m and s tables. Thus, MATRIX- CHAINORDER is much more efficient than the exponential-time method of enumerating all possible parenthesizations and checking each one
  • 19.  In dynamic problem subproblems are dependent.  Dynamic-programming algorithms typically take advantage of overlapping subproblems by solving each subproblem once and then storing the solution in a table where it can be looked up when needed, using constant time per lookup.  Cost is reduced. (A1 *A2) (A3*(A4*A5)) (A1*A2) (A3*A4)*A5 ^ | Overlapping subproblem
  • 20.  A memoized recursive algorithm maintains an entry in a table for the solution to each subproblem. Each table entry initially contains a special value to indicate that the entry has yet to be filled in. When the subproblem is first encountered as the recursive algorithm unfolds, its solution is computed and then stored in the table. Each subsequent time that we encounter this subproblem, we simply look up the value stored in the table and return it