# Dynamic Programming

> Saving the answers to small parts that repeat. Each is solved once.

**Field:** Software Development  
**Category:** Algorithms & Data Structures  
**Also known as:** DP

## Think of it like

Think of it like a notebook of sums. Write each one down, so you never work it out twice.

## Definition

Dynamic programming breaks a big problem into small ones that repeat. It saves each small answer. When the same small problem comes up again, it reuses the saved answer. You can save answers as you go from the top; that is called memoization. Or you can fill a table from the smallest case up. It turns many jobs that would take years into ones that take a second.

## Example

Jack works out the 50th Fibonacci number. Saving each smaller one makes 49 additions, not billions of calls.

## Why it matters

Route maps, spell checkers and DNA tests all use it. Without it, those jobs would never finish.

## Common mistake

Using it where the small parts never repeat. Saving answers then costs memory and saves nothing.

## Three principles

- **Small parts repeat.** That is the sign.
- **Save each answer.** Never solve twice.
- **Top down or bottom up.** Memo or table.

## Related terms

- [Memoization](https://learn.benibix.com/term/development/memoization)
- [Divide and Conquer](https://learn.benibix.com/term/development/divide-and-conquer)
- [Recursion](https://learn.benibix.com/term/development/recursion)
- [Greedy Algorithm](https://learn.benibix.com/term/development/greedy-algorithm)

## Told apart from

- [Divide and Conquer vs Dynamic Programming](https://learn.benibix.com/compare/divide-and-conquer-vs-dynamic-programming): Divide and conquer and dynamic programming both cut a big problem into small parts to solve one at a time. In the first, each part is new. In the second, the same parts come back, so each answer is saved and used again.
- [Greedy Algorithm vs Dynamic Programming](https://learn.benibix.com/compare/greedy-algorithm-vs-dynamic-programming): People think a greedy algorithm always finds the best answer, and it does not. Greedy takes the best-looking step now and never goes back. Dynamic programming works out the best answer for each smaller case first, then builds on them. Greedy is faster when it works. With coins of 4, 3 and 1, greedy makes 6 with three coins, and dynamic programming finds two.

---

Source: https://learn.benibix.com/term/development/dynamic-programming
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
