Dynamic Programming Flashcards

(17 cards)

1
Q

What are features of dynamic programming?

A

Possibly overlapping subproblems, used for optimization, top down is recursive, bottom up is iterative

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

What are some example problems?

A

Matrix chain multiplication, rod cutting, longest common subsequence

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

Given a sequence x of size n, and a sequence y of size m, how many possible subsequences are there?

A

2^m possible subsequences

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

What is a brute force approach to finding the longest common subsequence in y that appears in x?

A

Generating every possible subsequence and linearly checking x to see if it appears

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

What is one way to use dynamic programming to find the longest common subsequence in y that appears in x?

A

TopDown, if xn and ym match, then find the LCS of x and y without xn and ym, if they don’t match then find the bigger LCS between the sets x1…xn-1,y and the sets x,y1…y-m

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

How are the arrows from a handwritten LCS graph actually stored in a coded implementation?

A

The arrows are encoded as four values, one for each combination of arrows: left, up, diagonal upleft, and left+up

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

How much memory is actually needed to implement this LCS algorithm?

A

Only the 2-D array to hold the match data is needed, the other info can be computed using comparisons

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

How much memory is needed if you only want the score?

A

If the sequence alignment isn’t needed, only 2 1-D arrays are needed (2 rows)

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

What are the benefits of alignment?

A

Also keeps track of replacement cost, also known as edit distance

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

How long does it take to find the LCS from an S array?

A

O(nxm)

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

What is the Rod Cutting problem?

A

For a rod of length n, cut the rod into subrods such that the subrods are the correct lengths to maximize profits when sold

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

What is the complexity of a brute force approach to the Rod Cutting problem?

A

2^n-1, the amount of possible cut combinations

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

What is the complexity of a dynamic programming bottom up approach to the Rod Cutting problem?

A

n(n+1)/2

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

What is the bookkeeping for a bottom up approach to the Rod Cutting problem?

A

Subrod length, subrod price, subrod profit, optimal cut for subrod length

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

What is a bottom up approach to the Rod Cutting problem?

A

Subrod1 profit = subrod1 price
Subrod2 profit = max(subrod2 price, subrod1 price + subrod1 price)
Subrod3 profit = max(subrod3 price, subrod2 price + subrod1 profit, subrod2 profit + subrod1 price)
etc.

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

What is a top down approach to the Rod Cutting problem?

A

Log values of subproblems, then if encountered again, treat as base case

17
Q

Which dynamic programming approach is better for the Rod Cutting problem?

A

Bottom up, recursion unnecessary, faster to use iterative approach