dynamic programming Flashcards

1
Q

Is dynamic programming a recursive algorithm?

A

No.

Actually, recursion is a very bad idea: the resulting procedure would require exponential time!
Unlike divide-and-conquer reduce subproblems to a substantially smaller size. In contrast, in a typical dynamic programming formulation, a problem is reduced to subproblems that are only slightly smaller. For instance, L(j) relies on L(j - 1). Thus the full recursion tree generally has polynomial depth and an exponential number of nodes.

However, it turns out that most of these nodes are repeats, that there are not too many distinct subproblems among them. Efficiency is therefore obtained by explicitly enumerating the distinct subproblems and solving them in the right order.

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

pseudo-code for Longest Increasing Subsequences

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

pseudo-code for Longest Common Subsequence

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

pseudo-code for knapsack without repeat

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

pseudo-code for knapsack with repeat

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

pseudo-code for finding the minimum cost of Chain matrix multiplication

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

overall running time for finding the minimum cost of Chain matrix multiplication

A

O(n3)

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

overall running time for Knapsack

A

O(nB)

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

overall running time for Longest common subsequence

A

O(n2)

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

overall running time for Longest increasing subsequences

A

O(n2)

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

pseduo-code for bellman-ford: single-source shortest paths

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

GigO time for bellman-ford: all-pairs shortest paths

A

O(|V|3)

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

Pseudo-code for Floyd-Warshall algorithm

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

Algorithms difference between Knapsack with and without repetition

A

Knapsack with repetition can be reduced to one dimension.

for w = 1 to W:

K(w) = max{K(w -wi) + vi : all wi <= w}

This algorithm fills in a one-dimensional table of length W + 1, in left-to-right order. Each entry can take up to O(n) time to compute, so the overall running time is O(nW).

Knapsack without repetition needs two dimensions.

K(w, j) = max{K(w - wj, j - 1) + vj , K(w, j - 1)}

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

running time for bellman-ford: single-source shortest paths

A

O(mn)

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