Skip to main content
The 2024 Developer Survey results are live! See the results

Dynamic programming is an algorithmic technique for efficiently solving problems which have recursive structure with many overlapping subproblems. Do NOT use this tag for general "dynamic" behavior in code.

The link between dynamic programming and recursion is actually very strong.

Any dynamic programming solution can be transformed into a recursive solution (with memoization), with identical performance characteristics, e.g O(n*n). The difference is primarily one of presentation.

In order to be amenable to dynamic programming, the formulation of a problem must have the optimal substructure property.

The longest common subsequence problem is a good example of a problem that can be solved with dynamic programming.