Dynamic programming Flashcards

1
Q

What is Dynamic Programming, and why is it important

A

Dynamic Programming (DP) is a problem-solving paradigm that involves breaking down complex problems into smaller, overlapping sub-problems and storing the results to avoid redundant computations. This approach is used to solve problems with optimal sub-structures and overlapping sub-problems, leading to efficient solutions by reusing previously computed results. The importance of DP lies in its ability to improve computational efficiency, especially for problems with exponential complexity.

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

What are the key ingredients for a problem to be suitable for Dynamic Programming?

A

A problem is suitable for Dynamic Programming if it has two key characteristics:

Optimal sub-structures: The solution to the larger problem can be constructed from the solutions to smaller sub-problems.
Overlapping sub-problems: The same sub-problems are encountered multiple times, allowing for the reuse of previously computed results.

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

What are the steps involved in solving a problem with Dynamic Programming?

A

The following steps outline how to solve a problem with Dynamic Programming:

Define sub-problems: Identify the smaller sub-problems that can be solved recursively.
Write the recurrence relation: Establish a relation between the sub-problems and the original problem.
Recognize and solve the base cases: Determine the simplest cases and their solutions.
Implement a solving methodology: Choose between top-down (memoization) or bottom-up (tabulation) approaches for solving the problem.

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

What is the difference between the top-down (memoization) and bottom-up (tabulation) approaches in Dynamic Programming?

A

Top-Down (Memoization): This approach starts with a recursive function and caches the results of each sub-problem. Before recomputing a sub-problem, the cached result is checked, reducing redundant computations. It has less overhead for recursive calls but can be slower due to recursive function calls.
Bottom-Up (Tabulation): This approach iterates from the base cases to the larger problem, filling a DP table with computed results in an order that ensures dependencies are resolved. It is generally faster due to avoiding recursive calls but can require more memory to store the table.

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

What is the main idea behind memoization in the context of Dynamic Programming?

A

Memoization in Dynamic Programming involves storing the results of computed sub-problems in a data structure, typically an array or a dictionary. This cached information is then used to avoid re-computation when the same sub-problems are encountered again. The primary benefit is increased efficiency by reducing redundant calculations, leading to a more efficient algorithm.

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

How can you identify when Dynamic Programming is a suitable approach for solving a problem?

A

Dynamic Programming is suitable when a problem exhibits optimal sub-structures and overlapping sub-problems. To determine if DP is appropriate, consider these factors:

Recurrence relation: If the problem can be broken down into smaller sub-problems with a clear relation between them.
Overlapping sub-problems: If the same sub-problems are encountered multiple times, allowing for the reuse of computed results.
Optimization goals: If the problem seeks to optimize a specific metric (e.g., weight, cost, or length), indicating a suitable structure for DP.
If these conditions are met, DP can be used to improve computational efficiency and reduce redundant computations.

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