dynamic programming Flashcards
what is dynamic programming
Dynamic Programming is an algorithm design technique
for optimization problems
– Often minimizing or maximizing an answer
- Reusing computation
Contrast the Divide and Conquer and Dynamic Programming
approaches to solving problems
Like Divide & Conquer, DP solves problems by combining
solutions to subproblems, they are recursive
Unlike Divide & Conquer, subproblems are not independent. Overlapping or repeated subproblems, DP has optimization, DP has storage
D&C solves independent subproblems recursively, while DP solves overlapping subproblems and stores their solutions
Identify when Dynamic Programming should be used to solve a problem
Properties of a problem that can be solved
with DP
- Simple Subproblems
– We should be able to break the original problem to
smaller subproblems that have the same structure - Optimal Substructure of the problems
– The solution to the problem must be a composition
of subproblem solutions - Subproblem Overlap
– Same subproblems are solved multiple times during
the computation process
Define the Principle of Optimality
- The principle of optimality is applied in a problem if
an optimal solution for a problem includes optimal solutions
for all sub-problems - If the principle holds, we can provide a recursive solution
and obtain optimal solutions from smaller ones
what is the difference between memoization and tabulation in DP?
memoization uses a top down approach, while tabulation uses a bottom up approach
what does matrix chain multiplication solve
given n matrices, what is the least expensive order to multiply them in
what does the knapsack problem solve
how to maximize the total value of items while the total weight remains below the limit
what does longest common subsequence problem solve
To find one of the longest common subsequences of a pair of sequences
what does optimal binary search trees solve
Want to build a binary search tree (BST) with
minimum expected search cost.
Expected search cost is based on probability that we are searching for a given value, and its height.