SlideShare a Scribd company logo
1 of 17
Dynamic
Programming
Contents
Introduction
Elements of
Dynamic Programming
Bibliography &
References
Introduction
*picture taken from https://www.engadget.com/2019/03/22/mit-ai-automated-neural-network-design/ on April, 2019
Dynamic Programming, like the divide – and – conquer method, solves
problems by combining the solutions to subsproblems.
Partitioning the problems into smaller part ( can be called as
subproblems ) solving them recursively then combining the solution to
solve the original Problems.
This method is usually applied for solving optimization problems.
Definition
Characterize the structure of an Optimal Solution.
Recursively define the value of an Optimal Solution.
Compute the value of an Optimal Solution, typically in a bottom-up
fashion.
Construct an optimal solution from computed information.
Sequence of Four Steps
Elements of
Dynamic Programming
*picture taken from http://www.consorzioc2t.it/attivita-scientifica/centro-ricerca-ict/ on April, 2019
Problems that having Optimal Substructure Property, if it is Optimum
Solution from that problems can be structured using Optimal Structure
from that sub-problems.
Optimal Substructure
Says that a stick that have length of n, divided into smaller part and have
variety of price depending on the length. Like below :
Optimal Substructure
Determine the Maximum revenue that can be reach from selling all parts of the
stick!
.
Lets pretend that value of n is 4 so, the probability of the revenue that can be
get is :
Optimal Substructure
4 Parts with length of 1. Revenue = 1 x 4 = 4
2 Parts with length of 1 and 1 Part with length of 2. Revenue = 2 x 1 + 5 = 7.
1 Part with length of 1 and 1 Part with length of 3. Revenue = 1 x 1 + 1 x 8 = 9.
2 Parts with length of 2. Revenue = 2 x 5 = 10.
1 Part with length of 4. Revenue = 1 x 9 = 9.
If Recursive subproblem is revisited multiple times, it can be optimized
by remembering the solution of that subproblem.
Overlapping Subproblems
Overlapping Subproblems
F[5]
F[3]F[4]
F[3] F[2]
F[2] F[1] F[0]
F[1] F[0]
F[2] F[1]
F[1] F[0]
Fibonacci Sequence
Runs like a normal recursion problem.
But checks a lookup table before
computing its solutions.
Saves its solution on the lookup table
after its computation.
Only has a solution to a problem that it
has faced.
Overlapping Subproblems
Memoization ( Top – Down )
Method
Runs the problem from the bottom of the
recursion.
Checks the lookup table before creating a
solution.
Save every solution along the way to the
lookup table.
Has every solution below the specified
subproblem.
Tabulation ( Bottom – Up )
Method
Use the table s[ i, j ] saves a significant amount of work when reconstructing an optimal solution
for matrix-chain multiplication.
Suppose that we did not maintain the s[ i, j ] table, having filled in only the table m[ i, j ]
containing optimal subproblem costs. It would take θ ( j – i ) = ω ( 1 ) time to reconstruct.
By storing in s[ i, j ] the index of the matrix at which we split the product Ai, Ai+1, …..Aj , we
can reconstruct each choice in O ( 1 ) time.
Reconstructing an optimal solution
oized version of RECURSIVE-MATRIX-CHAIN with top-down method.
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.
Memoization
Memoized version of RECURSIVE-
MATRIX-CHAIN with top-down method.
Like the bottom-up dynamic-programming algorithm MATRIX-CHAIN-ORDER, the procedure
MEMOIZED-MATRIX-CHAIN runs in O(n3)time. Line 5 of MEMOIZED-MATRIX-CHAIN
executes θ (n2) times.
In general practice, if all subproblems must be solved at least once, a bottom-up dynamic-
programming algorithm usually outperforms the corresponding top-down memoized algorithm
by a constant factor, because the bottom-up algorithm has no overhead for recursion and less
overhead for maintaining the table.
Memoization
Bibliography and
References
*picture taken from http://fortune.com/2015/09/24/ebook-sales/ on April, 2019
Thomas H. Cormen, “Introduction to Algorithms”, 3rd
Edition, MIT Press, 2009. ( Page 359 – 360, 378 – 390 )
"Overlapping Subproblems Property in Dynamic Programming
DP-1 GeeksforGeeks", GeeksforGeeks, 2019. [Online].
Available: https://www.geeksforgeeks.org/overlapping
subproblems-property-in-dynamic-programming-dp-1/
[Accessed: 29- Apr- 2019]
[1]
[2]

More Related Content

What's hot

Our presentation on algorithm design
Our presentation on algorithm designOur presentation on algorithm design
Our presentation on algorithm design
Nahid Hasan
 
Lecture 8 dynamic programming
Lecture 8 dynamic programmingLecture 8 dynamic programming
Lecture 8 dynamic programming
Oye Tu
 

What's hot (20)

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)
 
Algorithmic research
Algorithmic researchAlgorithmic research
Algorithmic research
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 
DP
DPDP
DP
 
Algorithm Design Presentation
Algorithm Design PresentationAlgorithm Design Presentation
Algorithm Design Presentation
 
Dynamic programming prasintation eaisy
Dynamic programming prasintation eaisyDynamic programming prasintation eaisy
Dynamic programming prasintation eaisy
 
Our presentation on algorithm design
Our presentation on algorithm designOur presentation on algorithm design
Our presentation on algorithm design
 
Dynamic programming in Algorithm Analysis
Dynamic programming in Algorithm AnalysisDynamic programming in Algorithm Analysis
Dynamic programming in Algorithm Analysis
 
Dynamic Programming
Dynamic ProgrammingDynamic Programming
Dynamic Programming
 
Matlab 4
Matlab 4Matlab 4
Matlab 4
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 
Algorithm Design
Algorithm DesignAlgorithm Design
Algorithm Design
 
Linear Programming
Linear  ProgrammingLinear  Programming
Linear Programming
 
DS ppt
DS pptDS ppt
DS ppt
 
Linear Programming Problem
Linear Programming ProblemLinear Programming Problem
Linear Programming Problem
 
Solving linear programming model by simplex method
Solving linear programming model by simplex methodSolving linear programming model by simplex method
Solving linear programming model by simplex method
 
dynamic programming Rod cutting class
dynamic programming Rod cutting classdynamic programming Rod cutting class
dynamic programming Rod cutting class
 
Lecture 8 dynamic programming
Lecture 8 dynamic programmingLecture 8 dynamic programming
Lecture 8 dynamic programming
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 
linear programming
linear programming linear programming
linear programming
 

Similar to Algorithm_Dynamic Programming

Module 2ppt.pptx divid and conquer method
Module 2ppt.pptx divid and conquer methodModule 2ppt.pptx divid and conquer method
Module 2ppt.pptx divid and conquer method
JyoReddy9
 
Ch3(1).pptxbbbbbbbbbbbbbbbbbbbhhhhhhhhhh
Ch3(1).pptxbbbbbbbbbbbbbbbbbbbhhhhhhhhhhCh3(1).pptxbbbbbbbbbbbbbbbbbbbhhhhhhhhhh
Ch3(1).pptxbbbbbbbbbbbbbbbbbbbhhhhhhhhhh
danielgetachew0922
 
Solving Optimization Problems using the Matlab Optimization.docx
Solving Optimization Problems using the Matlab Optimization.docxSolving Optimization Problems using the Matlab Optimization.docx
Solving Optimization Problems using the Matlab Optimization.docx
whitneyleman54422
 
2-Algorithms and Complexit data structurey.pdf
2-Algorithms and Complexit data structurey.pdf2-Algorithms and Complexit data structurey.pdf
2-Algorithms and Complexit data structurey.pdf
ishan743441
 

Similar to Algorithm_Dynamic Programming (20)

Module 2ppt.pptx divid and conquer method
Module 2ppt.pptx divid and conquer methodModule 2ppt.pptx divid and conquer method
Module 2ppt.pptx divid and conquer method
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 
Algorithms practice and problem solving - dynamic programming
Algorithms practice and problem solving - dynamic programmingAlgorithms practice and problem solving - dynamic programming
Algorithms practice and problem solving - dynamic programming
 
Computer algorithm(Dynamic Programming).pdf
Computer algorithm(Dynamic Programming).pdfComputer algorithm(Dynamic Programming).pdf
Computer algorithm(Dynamic Programming).pdf
 
6-Python-Recursion PPT.pptx
6-Python-Recursion PPT.pptx6-Python-Recursion PPT.pptx
6-Python-Recursion PPT.pptx
 
Algorithms Design Patterns
Algorithms Design PatternsAlgorithms Design Patterns
Algorithms Design Patterns
 
Divide and Conquer / Greedy Techniques
Divide and Conquer / Greedy TechniquesDivide and Conquer / Greedy Techniques
Divide and Conquer / Greedy Techniques
 
ADA Unit 2.pptx
ADA Unit 2.pptxADA Unit 2.pptx
ADA Unit 2.pptx
 
complexity analysis.pdf
complexity analysis.pdfcomplexity analysis.pdf
complexity analysis.pdf
 
9 - DynamicProgramming-plus latihan.ppt
9 - DynamicProgramming-plus latihan.ppt9 - DynamicProgramming-plus latihan.ppt
9 - DynamicProgramming-plus latihan.ppt
 
Ch3(1).pptxbbbbbbbbbbbbbbbbbbbhhhhhhhhhh
Ch3(1).pptxbbbbbbbbbbbbbbbbbbbhhhhhhhhhhCh3(1).pptxbbbbbbbbbbbbbbbbbbbhhhhhhhhhh
Ch3(1).pptxbbbbbbbbbbbbbbbbbbbhhhhhhhhhh
 
DS & Algo 6 - Dynamic Programming
DS & Algo 6 - Dynamic ProgrammingDS & Algo 6 - Dynamic Programming
DS & Algo 6 - Dynamic Programming
 
Dynamic Programming.pptx
Dynamic Programming.pptxDynamic Programming.pptx
Dynamic Programming.pptx
 
lecture4-recursion.pptx
lecture4-recursion.pptxlecture4-recursion.pptx
lecture4-recursion.pptx
 
Solving Optimization Problems using the Matlab Optimization.docx
Solving Optimization Problems using the Matlab Optimization.docxSolving Optimization Problems using the Matlab Optimization.docx
Solving Optimization Problems using the Matlab Optimization.docx
 
Divide and conquer algorithm
Divide and conquer algorithmDivide and conquer algorithm
Divide and conquer algorithm
 
DAA-Module-5.pptx
DAA-Module-5.pptxDAA-Module-5.pptx
DAA-Module-5.pptx
 
Dynamic Programming - Part 1
Dynamic Programming - Part 1Dynamic Programming - Part 1
Dynamic Programming - Part 1
 
Daa chapter 3
Daa chapter 3Daa chapter 3
Daa chapter 3
 
2-Algorithms and Complexit data structurey.pdf
2-Algorithms and Complexit data structurey.pdf2-Algorithms and Complexit data structurey.pdf
2-Algorithms and Complexit data structurey.pdf
 

Recently uploaded

Recently uploaded (20)

Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 

Algorithm_Dynamic Programming

  • 3. Introduction *picture taken from https://www.engadget.com/2019/03/22/mit-ai-automated-neural-network-design/ on April, 2019
  • 4. Dynamic Programming, like the divide – and – conquer method, solves problems by combining the solutions to subsproblems. Partitioning the problems into smaller part ( can be called as subproblems ) solving them recursively then combining the solution to solve the original Problems. This method is usually applied for solving optimization problems. Definition
  • 5. Characterize the structure of an Optimal Solution. Recursively define the value of an Optimal Solution. Compute the value of an Optimal Solution, typically in a bottom-up fashion. Construct an optimal solution from computed information. Sequence of Four Steps
  • 6. Elements of Dynamic Programming *picture taken from http://www.consorzioc2t.it/attivita-scientifica/centro-ricerca-ict/ on April, 2019
  • 7. Problems that having Optimal Substructure Property, if it is Optimum Solution from that problems can be structured using Optimal Structure from that sub-problems. Optimal Substructure
  • 8. Says that a stick that have length of n, divided into smaller part and have variety of price depending on the length. Like below : Optimal Substructure Determine the Maximum revenue that can be reach from selling all parts of the stick!
  • 9. . Lets pretend that value of n is 4 so, the probability of the revenue that can be get is : Optimal Substructure 4 Parts with length of 1. Revenue = 1 x 4 = 4 2 Parts with length of 1 and 1 Part with length of 2. Revenue = 2 x 1 + 5 = 7. 1 Part with length of 1 and 1 Part with length of 3. Revenue = 1 x 1 + 1 x 8 = 9. 2 Parts with length of 2. Revenue = 2 x 5 = 10. 1 Part with length of 4. Revenue = 1 x 9 = 9.
  • 10. If Recursive subproblem is revisited multiple times, it can be optimized by remembering the solution of that subproblem. Overlapping Subproblems
  • 11. Overlapping Subproblems F[5] F[3]F[4] F[3] F[2] F[2] F[1] F[0] F[1] F[0] F[2] F[1] F[1] F[0] Fibonacci Sequence
  • 12. Runs like a normal recursion problem. But checks a lookup table before computing its solutions. Saves its solution on the lookup table after its computation. Only has a solution to a problem that it has faced. Overlapping Subproblems Memoization ( Top – Down ) Method Runs the problem from the bottom of the recursion. Checks the lookup table before creating a solution. Save every solution along the way to the lookup table. Has every solution below the specified subproblem. Tabulation ( Bottom – Up ) Method
  • 13. Use the table s[ i, j ] saves a significant amount of work when reconstructing an optimal solution for matrix-chain multiplication. Suppose that we did not maintain the s[ i, j ] table, having filled in only the table m[ i, j ] containing optimal subproblem costs. It would take θ ( j – i ) = ω ( 1 ) time to reconstruct. By storing in s[ i, j ] the index of the matrix at which we split the product Ai, Ai+1, …..Aj , we can reconstruct each choice in O ( 1 ) time. Reconstructing an optimal solution
  • 14. oized version of RECURSIVE-MATRIX-CHAIN with top-down method. 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. Memoization Memoized version of RECURSIVE- MATRIX-CHAIN with top-down method.
  • 15. Like the bottom-up dynamic-programming algorithm MATRIX-CHAIN-ORDER, the procedure MEMOIZED-MATRIX-CHAIN runs in O(n3)time. Line 5 of MEMOIZED-MATRIX-CHAIN executes θ (n2) times. In general practice, if all subproblems must be solved at least once, a bottom-up dynamic- programming algorithm usually outperforms the corresponding top-down memoized algorithm by a constant factor, because the bottom-up algorithm has no overhead for recursion and less overhead for maintaining the table. Memoization
  • 16. Bibliography and References *picture taken from http://fortune.com/2015/09/24/ebook-sales/ on April, 2019
  • 17. Thomas H. Cormen, “Introduction to Algorithms”, 3rd Edition, MIT Press, 2009. ( Page 359 – 360, 378 – 390 ) "Overlapping Subproblems Property in Dynamic Programming DP-1 GeeksforGeeks", GeeksforGeeks, 2019. [Online]. Available: https://www.geeksforgeeks.org/overlapping subproblems-property-in-dynamic-programming-dp-1/ [Accessed: 29- Apr- 2019] [1] [2]