Day 78: Top-Down vs Bottom-Up DP – When to Pick What? 
You’ve probably seen both styles of Dynamic Programming—top-down (with memoization) and bottom-up (with tabulation). But when should you use which? Let’s break it down.
Top-Down (Memoization)
Recursive + memoization (usually with a Map or array)
Solves only the necessary subproblems
Easier to write, more intuitive
js
CopyEdit
function climbStairs(n, memo = {}) {
if (n <= 2) return n;
if (memo[n]) return memo[n];
return memo[n] = climbStairs(n - 1, memo) + climbStairs(n - 2, memo);
}
Great for:
Problems with sparse subproblem usage
Quick implementation and clarity
Bottom-Up (Tabulation)
Iterative approach using a table/array
Solves all subproblems in order
Typically more space/time efficient
js
CopyEdit
function climbStairs(n) {
const dp = [1, 1];
for (let i = 2; i <= n; i++) {
dp[i] = dp[i - 1] + dp[i - 2];
}
return dp[n];
}
Great for:
Performance-critical code
When full control over iteration is needed
Final Tip
Start with top-down when exploring a problem
Refactor to bottom-up if you hit time/space issues
100daysofcode lebanon-mug