Animation10 min

Filling the 1-D Table

Each cell built from the cells before it.

This animation fills a row of dp cells, left to right, above the input array — the bottom-up tabulation loop made visible.

For each new cell, watch three beats. First, glowing arrows reach back to the cells it depends on — the two previous cells for a Fibonacci-style recurrence, or every earlier cell with a smaller value in LIS mode. Those arrows are the recurrence: they show exactly which already-answered subproblems this one is built from. Second, a floating expression shows the arithmetic being applied, like max(4, 2 + 3) = 5 for House Robber's rob-or-skip choice. Third, the result stamps into the cell, permanently — a stamped cell is a solved subproblem that will never be recomputed.

Notice that no cell is ever touched twice. That is the entire speed story: the naive recursion revisits these same subproblems exponentially many times, while the table answers each one exactly once.

In LIS mode, one extra layer appears: as cells fill, the actual longest increasing subsequence found so far is drawn as a highlighted staircase over the input array — so you can see which elements the numbers in the table are counting.