Algorithms / 10 visualizations
Dynamic Programming Visualizers
Tables that remember answers: 1D and 2D DP step by step.
Open the lab → Every one runs on your own input, step by step, with the code highlighted in Java, Python, C++, C or JavaScript. Free, no sign-up.
All dynamic programming visualizations
- Fibonacci with MemoizationO(n)
fib(n) = fib(n − 1) + fib(n − 2). Plain recursion recomputes the same values and makes about 2^n calls. A memo map stores each answer, so every n is computed once and repeats are instant.
- Climbing StairsO(n)
Fill a table from the smallest case up. Each cell reuses cells you already filled, so nothing is computed twice.
- House RobberO(n)
best[i] is the most money from the first i houses. Either skip house i (keep best[i − 1]) or rob it and add it to best[i − 2]. Take the bigger one.
- Coin ChangeO(n·k)
dp[i] is the fewest coins for amount i. For each coin c, amount i can be reached from i − c with one more coin.
- Longest Increasing SubsequenceO(n²)
dp[i] is the length of the longest increasing run that ends exactly at a[i]. Look back at every j < i with a smaller value and extend the best one.
- Word BreakO(n²)
dp[i] says whether the first i letters can be built from words. dp[0] is true (the empty start). dp[i] is true if some earlier dp[j] is true and the letters from j to i form a word.
- Unique Paths with ObstaclesO(R·C)
You can only enter a cell from above or from the left, so paths(r, c) = paths(r − 1, c) + paths(r, c − 1). An obstacle has 0 paths through it.
- 0/1 KnapsackO(n·W)
dp[i][w] is the best value using the first i items with capacity w. Either skip item i (cell above) or take it (value + the cell up and to the left).
- Longest Common SubsequenceO(m·n)
dp[i][j] is the LCS of the first i letters of A and the first j letters of B. A match adds 1 to the diagonal. Otherwise take the bigger of up and left.
- Edit DistanceO(m·n)
dp[i][j] is the cost to turn the first i letters of A into the first j letters of B. Same letter: copy the diagonal. Otherwise 1 + the cheapest of replace (diagonal), delete (up) or insert (left).