Dynamic Programming Mind Map

Algorithm & Systems Visualizations

Every dynamic programming visualization on this site on one map. The branches are the main ideas. Each leaf is a page; the grey line under it is the one thing to remember about it. Click a branch to focus on it, click a page to open it.

Recall mode hides the page names. Read the hint, say the name, then click the "?" to check.

1. How the map is organized

Overview of the dynamic programming mind map: Recursion to table, One-row DP, Knapsack family, Two strings, Grid DP, Interval DP, Unusual states, Trees and DAGs.
The map at a glance: 8 branches, 31 pages.

Ask what one table cell stands for, and you know the branch:

  • A prefix of one sequence? One-row DP. A prefix of items plus a capacity or sum: knapsack family.
  • Prefixes of two strings? Two strings. A cell of a picture-like grid: grid DP.
  • A range i..j that you split? Interval DP, filled by length. Anything stranger (eggs and floors, a subset of cities): unusual states.
  • Pages about how to run any DP (memo or table) sit on recursion to table.

2. The branches side by side

BranchStateFill orderTypical time
Recursion to tablea recursive call's argumentstop-down memo or bottom-upstates × work per state
One-row DPdp[i]left to rightO(n) to O(n²)
Knapsack familydp[i][w] items × capacityrow by rowO(n·W), pseudo-polynomial
Two stringsdp[i][j] prefixesrow by rowO(m·n)
Grid DPdp[r][c] celltop-left to bottom-rightO(m·n)
Interval DPdp[i][j] rangeby range lengthO(n³)
Unusual stateseggs × floors, subset × cityby subset or countHeld-Karp O(n²·2ⁿ)

3. Five facts to remember

  • DP needs two things: overlapping subproblems and optimal substructure.
  • Running time = number of states × work to compute one state.
  • Memoization (top-down) and tabulation (bottom-up) compute the same values in different orders.
  • Keep a choice table or trace back from the last cell to recover the actual answer, not just its value.
  • Knapsack's O(n·W) is pseudo-polynomial: it grows with the value of W, not its number of digits.

See all dynamic programming pages in the index, or the other mind maps.