dynamic programming Flashcards

1
Q

what is dynamic programming

A

Dynamic Programming is an algorithm design technique
for optimization problems
– Often minimizing or maximizing an answer
- Reusing computation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Contrast the Divide and Conquer and Dynamic Programming
approaches to solving problems

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Identify when Dynamic Programming should be used to solve a problem

A

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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Define the Principle of Optimality

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

what is the difference between memoization and tabulation in DP?

A

memoization uses a top down approach, while tabulation uses a bottom up approach

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

what does matrix chain multiplication solve

A

given n matrices, what is the least expensive order to multiply them in

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

what does the knapsack problem solve

A

how to maximize the total value of items while the total weight remains below the limit

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

what does longest common subsequence problem solve

A

To find one of the longest common subsequences of a pair of sequences

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

what does optimal binary search trees solve

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly