Dynamic Programing
Dynamic Programing
• Dynamic programming is typically applied to optimization problems. In such problem there can be
many solutions. Each solution has a value, and we wish to find a solution with the optimal value
Dynamic Programming is a general algorithm design technique for solving problems defined by or
formulated as
recurrences with overlapping sub instances.
Main idea:
- set up a recurrence relating a solution to a larger
instance to solutions of some smaller instances
- solve smaller instances once
- record solutions in a table
- extract solution to the initial instance from that table
• By “inefficient”, we mean that the same recursive call is made over and over.
• If same subproblem is solved several times, we can use table to store result of a subproblem the
first time it is computed and thus never have to recompute it again.
• Dynamic programming is applicable when the subproblems are dependent, that is, when
subproblems share subsubproblems
.• “Programming” refers to a tabular method
• Simple subproblems
– We should be able to break the original problem to smaller
subproblems that have the same structure
• Overlapping sub-problems
– there exist some places where we solve the same
subproblem more than once.
Steps to Designing a Dynamic Programming Algorithm
Principle of Optimality
• Principle of optimality states that in an optimal sequence of decisions or choices, each sub
sequences must also be optimal.
1. Dynamic Programming is used to 1. Greedy Method is also used to get the optim
obtain the optimal solution. al solution.
Examples: