Dynamic programming

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:

  1. Define the subproblems.
  2. Implement the recurrence that solves the subproblems (in ...

Get Learning JavaScript Data Structures and Algorithms - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.