DSA · interactive
Dynamic programming: solve small, reuse it
What is the fewest coins (1, 3, 4) that add up to an amount? Plain recursion asks the same small questions over and over. A table answers each one once, from 0 upward, and looks up the rest.
Filling amount 0 of 6
coins 1 · 3 · 4
- 00
- 1
- 2
- 3
- 4
- 5
- 6
- best[0] = 0, no coins needed
Start with the base case: making 0 takes 0 coins.
Amount
1 Making 0 takes 0 coins. Every other answer is built on top of this one.
best[0] = 0
2 3 4
Now solve it
Dynamic Programming: 18 problems
See all →In production
Tools and technologies
Dynamic programming shows up wherever a big choice splits into smaller ones that repeat.
Not tied to one language — use these names when you search docs or design a system.
- Optimal Round: DP problemsSoftware
Climbing stairs, coin change, edit distance and 15 more.
GitHub ↗ - git diffSoftware
Finds the smallest set of line edits between two files with a DP-style search.
Documentation ↗ - PostgreSQL query plannerSoftware
Picks the cheapest join order by building it up from smaller joins.
Documentation ↗