01Chapter 1: Where DP Memory Goes: States, Transitions, and TablesDynamic programming (DP) makes slow recursive solutions fast by storing answers to subproblems and reusing them. The stored answers cost memory, and the cost is often far larger than people expect. A solution that runs in a few seconds can still fail because its table does not fit in RAM.5 min read
02Chapter 2: Reading the Dependency Pattern of a RecurrenceThis chapter assumes you can write a bottom-up DP table, read a recurrence such as the one for longest common subsequence (LCS), and reason about Big-O space. Every memory reduction later in this tutorial rests on one question: when the algorithm computes a state, which earlier states does it read? 6 min read
03Chapter 3: Constant Space with Rolling VariablesThis chapter assumes you can write a bottom-up DP table and state its time and space in Big-O terms. It also assumes you have read the previous chapter on dependency analysis, which covered finding which earlier states a transition reads. Here we use that analysis on the simplest case: a one-dimensi6 min read
04Chapter 4: From a Full Table to Two RowsThis chapter assumes you can write a bottom-up DP table for a two-dimensional problem such as longest common subsequence (LCS), and that you can read a recurrence and say which cells it reads, as covered in the dependency-analysis chapter. You also need Big-O space analysis and Python lists.6 min read
05Chapter 5: One Array, Updated in Place: Why Loop Direction MattersThe previous chapter cut a 2D table down to two rows: one for the previous layer and one for the current layer. This chapter goes one step further and keeps a single array. The new problem is that old and new values now share the same cells. Whether a read returns the old value or the new one depend6 min read
06Chapter 6: Keeping the Diagonal: Single-Row Edit DistanceThis chapter assumes you know the edit distance recurrence and its usual full-table solution. It also builds on the two earlier chapters on two-row rolling arrays and on loop direction for in-place updates. Here you will fold a two-dimensional table into one array, even though the recurrence reads a6 min read
07Chapter 7: Keeping the Last k Layers with Modulo IndexingThis chapter assumes you know rolling variables for one-dimensional recurrences and two-row rolling arrays for two-dimensional tables, both covered earlier. It also assumes you can read a recurrence and list which earlier states it depends on. Here we generalize both ideas. When a recurrence looks b6 min read
08Chapter 8: Removing State Dimensions You Can DeriveThis chapter assumes you can write a bottom-up DP table, read a recurrence's dependency pattern (covered earlier in this tutorial), and apply rolling rows. The techniques so far shrink a table along the direction the loop moves. This chapter shrinks it in a different way. It removes a whole dimensio6 min read
09Chapter 9: Collapsing State into a Small State MachineThis chapter assumes you are comfortable with bottom-up tabulation, with rolling variables for one-dimensional recurrences, and with tuple assignment in Python (a, b = b, a + b). It also builds on the previous chapter's idea that a state dimension can sometimes be removed.6 min read
10Chapter 10: Compact Subset States with BitmasksThis chapter assumes you can already write a bottom-up DP table and analyze its space in Big-O terms. It also assumes you have read the chapter on removing derivable state dimensions, because the main memory saving here comes from that idea. You should also be comfortable with Python's integer bitwi6 min read
11Chapter 11: Storing Only Reachable StatesThe earlier chapters shrank DP tables by throwing away layers that no later transition reads. This chapter targets a different waste. Many dense tables are mostly empty, because most indices never correspond to any state the recurrence can actually produce. If you store only the states that are reac6 min read
12Chapter 12: The Hidden Memory Cost of Top-Down MemoizationThis chapter assumes you can write a memoized recursive function, read Big-O space bounds, and know the 0/1 knapsack and LCS recurrences. Earlier chapters cut memory by discarding table rows the recurrence no longer reads. Top-down memoization cannot do that. The sections below show where its memory6 min read
13Chapter 13: Getting the Answer Back: Reconstruction After CompressionEarlier chapters cut DP memory by keeping only the rows or variables that a transition reads. That works when you only need the optimal value, such as the LCS length or the best knapsack total. Many real tasks also need the solution itself: which items to pack, which characters form the subsequence,6 min read
14Chapter 14: Hirschberg's Algorithm: Linear Space with Full ReconstructionThe previous chapter showed the usual trade-off. If you keep only two rows of the longest common subsequence (LCS) table, you get the length of the LCS in O(min(m, n)) space, but you lose the backtracking path that spells out the subsequence itself. Hirschberg's algorithm removes that trade-off. It 6 min read
15Chapter 15: Choosing the Right Reduction for a RecurrenceThis chapter pulls the earlier techniques together into one decision process. It assumes you have worked through the previous chapters. You should be able to read a recurrence's dependency pattern, and you should know rolling variables, two-row and single-row arrays, loop direction, the saved diagon6 min read