Memoization vs. Tabulation
Memoization vs. Tabulation
- Memoization (top-down): write a recursive solution and cache results to avoid recomputation
- Tabulation (bottom-up): iteratively fill a DP table from base cases up to the answer
Example (Fibonacci):
// Memoization
function fibMemo(n, memo = []){
if (n<=1) return n
if (memo[n]!=null) return memo[n]
return memo[n] = fibMemo(n-1,memo) + fibMemo(n-2,memo)
}
// Tabulation
function fibTab(n){
const dp = Array(n+1).fill(0); dp[1]=1
for (let i=2;i<=n;i++) dp[i]=dp[i-1]+dp[i-2]
return dp[n]
}
Choose based on convenience, stack limits, and whether you need all states or just the final result.
Up next · Lesson 81 of 92
Classic DP Problems (Fibonacci, Knapsack, Longest Common Subsequence)
1 min read
80 of 92 lessons done

Ask Byte about this lesson
A private chat about this lesson. Byte has read the whole lesson, answers in seconds, and shows the section each answer comes from. Ask follow-ups in any language.
Questions & Answers
Public questions about this lesson. The AI Tutor answers right away in your language, the FreeAcademy team checks answers, and every learner can read them.

