DSA · Patterns, not puzzles
What is the difference between memoization and tabulation?
Short answer
Memoization is top-down recursion that caches results. Tabulation is bottom-up iteration that fills a table. Both avoid repeated work; memoization is easier to write from a recurrence, tabulation avoids recursion depth.
They are two directions through the same state graph. Memoization starts at the requested state and recurses into dependencies, storing answers on the way back. Tabulation starts at the base states and computes forward until the target state is ready.
function fibMemo(n, memo = new Map()) {
if (n <= 1) return n;
if (memo.has(n)) return memo.get(n);
const value = fibMemo(n - 1, memo) + fibMemo(n - 2, memo);
memo.set(n, value);
return value;
}
function fibTab(n) {
if (n <= 1) return n;
let prev = 0;
let current = 1;
for (let i = 2; i <= n; i++) {
const next = prev + current;
prev = current;
current = next;
}
return current;
}Choosing between them
- Memoization follows the recurrence directly and is easy to reason about
- Tabulation avoids recursion limits and often has better constants
- Memoization may skip states that the target never needs
- Tabulation may compute states that are not required
- Some state graphs are easier to express top-down, especially with pruning
Space can often be reduced in the tabulated version. If each state depends only on the previous row or the previous two values, keep rolling variables instead of the full table. The same reduction is harder to see in the recursive version.
Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1Which approach is easier to debug?
- 2How do you reduce a two-dimensional DP table to one dimension?
- 3What are the risks of deep memoized recursion?
- 4Can you use memoization with mutable state?
Say it in the interview
Memoization is top-down: I write the recurrence recursively and cache each result. Tabulation is bottom-up: I fill a table from the base cases up to the answer. I usually start with memoization because it mirrors the recurrence, then convert to tabulation if recursion depth or overhead is a problem. Tabulation also makes space reduction easier.
Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.
Related questions
Reading is step one
Now say it out loud.
Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live DSA mock interview and get scored feedback on depth, clarity and confidence.