Dynamic Programming Flashcards
What is dynamic programming?
Dynamic programming solves problems by combining the solutions to subproblems
What is the difference between DP and divide-and-conquer?
D&C algorithms partition the problem into disjoint subproblems, solve the subproblems recursively, and then combine their solutions to solve the original problem.
In contrast, DP applies when the subproblems overlap - that is, when subproblems share subsubproblems.
In this context, a D&C algorithm does more work than necessary, repeatedly solving the common subsubproblems.
What are the steps do develop a DP algorithm?
- 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
What are key characteristics a optimization problem must have in order for DP to apply?
- Optimal substructure
2. Overlapping subproblems
What does ‘optimal substructure’ mean in the context of DP?
A problem exhibits optimal substructure if an optimal solution to the problem contains within it optimal solutions to subproblems.
What does ‘overlapping subproblems’ mean in the context of DP?
When a recursive algorithm revisits the same problem repeatedly, we say that the optimization problem has overlapping subproblems. DP 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.