Algorithms Lecture
Algorithms Lecture
Lecture 5
DYNAMIC PROGRAMMING
Main idea:
o Set up a recurrence relating a solution to a larger instance to solutions of some
smaller instances
o Solve smaller instances once
o Record solutions in a table
o Extract solution to the initial instance from that table
Major components of DP
Greedy technique focuses on expanding partially constructed solutions until you arrive at a
solution for a complete problem. It is then said, it must be "the best local choice among all
feasible choices available on that step".
Optimal substructure means that you can greedily solve subproblems and combine the solutions
to solve the larger problem. The difference between dynamic programming and greedy
algorithms is that with dynamic programming, there are overlapping subproblems, and
those subproblems are solved using memoization. "Memoization" is the technique whereby
solutions to subproblems are used to solve other subproblems more quickly.
Example: