Dynamic programming (DP) is an optimization technique used to solve complex problems by breaking them into smaller subproblems.
Note that the dynamic programming approach is different from the divide and conquer approach. While the divide and conquer approach breaks the problem into independent subproblems and then combines the solutions, dynamic programming breaks the problem into dependent subproblems.
An example of a dynamic programming algorithm is the Fibonacci problem we solved in Chapter 9, Recursion. We broke the Fibonacci problem into smaller problems.
There are three important steps we need to follow when solving problems with DP:
- Define the subproblems.
- Implement the recurrence that solves the subproblems (in this step, we need to follow the steps for recursion that we discussed in the previous section).
- Recognize and solve the base cases. ...