Week 2 Flashcards

(28 cards)

1
Q

What is dynamic programming?

A

A method for solving optimization problems by breaking them into subproblems and building solutions using optimal substructure and overlapping subproblems.

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

What does ‘programming’ refer to in dynamic programming?

A

In this context, ‘programming’ means scheduling or decision-making, not coding.

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

What are key applications of dynamic programming?

A

Shortest path algorithms, computational biology, resource allocation problems.

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

What is optimal substructure?

A

A problem has optimal substructure if the optimal solution can be constructed from optimal solutions of its subproblems.

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

What are the three parts of optimal substructure?

A
  1. Sequence of decisions. 2. Subproblem is an instance of the original. 3. Final solution combines decision + subproblem solution.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the rod cutting problem?

A

Given a rod of length L and a price table for rod pieces, determine how to cut the rod to maximize revenue.

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

What are the inputs of the rod cutting problem?

A

Rod length L and a price table of rod lengths and prices.

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

What is the goal of the rod cutting problem?

A

Maximize total revenue by optimally cutting the rod into pieces based on price table.

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

What is the recurrence formula for max revenue in rod cutting?

A

maxRevenue(L) = max(0, p1 + maxRevenue(L - l1), …, pn + maxRevenue(L - ln))

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

What are the base cases in the rod cutting recurrence?

A

maxRevenue(0) = 0; maxRevenue(L < 0) = -∞ (invalid length)

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

Why is naive recursion inefficient in dynamic programming?

A

Because it leads to repeated computation of the same subproblems (overlapping subproblems).

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

What are two techniques to avoid redundant computation in DP?

A

Memoization (top-down with cache) and bottom-up dynamic programming.

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

What is memoization?

A

Caching results of subproblems to avoid recomputation in recursive dynamic programming.

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

What is bottom-up dynamic programming?

A

An iterative approach that solves smaller subproblems first and builds up to the full problem.

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

What are signs a problem is suitable for dynamic programming?

A

It has optimal substructure, overlapping subproblems, and a recurrence relation.

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

What does the rod cutting DP recurrence represent?

A

The maximum revenue for a rod of length L by trying all valid cuts and combining them with subproblem solutions.

17
Q

What are the four steps of dynamic programming?

A
  1. Identify optimal substructure
  2. Write the recurrence (value function)
  3. Memoize the results
  4. Recover the solution
18
Q

What is the value function in dynamic programming?

A

A recurrence relation that expresses the optimal value of a problem in terms of its subproblems.

19
Q

Why is memoization important in dynamic programming?

A

It avoids redundant computation by storing and reusing results of overlapping subproblems.

20
Q

What base case is used for rod cutting problems when length < 0?

A

Assign -∞ to indicate invalid cuts (e.g., cutting more than the rod length).

21
Q

What is the recurrence relation for the rod cutting problem?

A

MaxRevenue(L) = max(0, MaxRevenue(L - l₁) + p₁, …, MaxRevenue(L - lₙ) + pₙ)

22
Q

What is the time complexity of the memoized rod cutting algorithm?

A

O(nL), where n is the number of cut options and L is the rod length.

23
Q

What is stored in the memoization table T[i]?

A

The maximum revenue achievable for a rod of length i.

24
Q

How is the S[i] table used in dynamic programming?

A

It stores the best decision (cut size) that leads to the optimal value at T[i].

25
How do you recover the solution from the memo and decision tables?
Trace back from S[L], subtracting the recorded decision until reaching 0.
26
What is the role of Bellman in dynamic programming?
Richard Bellman pioneered dynamic programming in the 1950s.
27
What real-world fields use dynamic programming beyond algorithms?
Optimal control, robotics, path planning, chemical plant control, and aircraft systems.
28
Why can’t arrays be indexed with negative numbers directly?
Because they are not valid indices. You must use conditionals to check and return -∞.