1) Examples:
Fibonacci Sequence: Compute the nth Fibonacci number efficiently using a table to store previously computed values.
Longest Common Subsequence: Find the longest subsequence that appears in two sequences.
Knapsack Problem: Determine the maximum value that can be obtained by selecting items with given weights and values, subject to a weight constraint.
Matrix Chain Multiplication: Determine the optimal order of multiplying a sequence of matrices to minimize the number of scalar multiplications.
Edit Distance: Calculate the minimum number of operations (insertions, deletions, substitutions) required to transform one string into another.
Optimal Binary Search Trees
Rod Cutting Problem
Longest Increasing Subsequence
Coin Change Problem
2) Overview:
A method for solving problems by breaking them down into smaller subproblems and solving them independently. (Optimal substructure)
The solutions to the subproblem are stored in memory and reused to solve the larger problem. (Overlapping subproblems)
==> Lead to significant improvements in performance compared to solving the problem from scratch each time.
3) Idea:
We can solve the subproblems efficiently and reuse their solutions.
We can avoid redundant work and reduce the time complexity of the overall problem.
4) Algorithm:
Identify the optimal substructures:
Define subproblems: Break down the problem into smaller subproblems that can be solved independently.
Define the base case: Determine the solutions to the simplest subproblems.
Define the recurrence relation: Express the solution to each subproblem in terms of the solutions to smaller subproblems.
Compute the subproblem solutions: Use the recurrence relation to compute the solutions to the subproblems, storing them in memory as needed.
Build the solution: Combine the solutions to the subproblems to form the solution to the original problem.
5) Advantage and Disadvantage:
Advantages: Dynamic programming guarantees an optimal solution by avoiding redundant calculations and exploring all possible subproblems.
Disadvantages: It might require a significant amount of memory to store solutions to subproblems in a table. In some cases, identifying the optimal substructure and recursive relation can be challenging.
References: