03.02 · Lesson
From Memo to Table
Memo works from the top down: start from the big question and let recursion reach the small ones. A table works from the bottom up: fill the small answers first in a loop. Same answers, same speed.
When to bother:
- The recursion can be very deep (thousands of calls): use a table.
- The question asks you to save memory: use a table plus two variables.
- Otherwise memo is fine in a test. Get the memo right first.
The 5 steps
| Step | Do |
|---|---|
| 1 | Same array, same size as the memo |
| 2 | Write the base-case answers into it |
| 3 | Loop so that the values you need are already filled |
| 4 | Copy the recurrence, with f(x) replaced by dp[x] |
| 5 | The answer is dp at the first call’s state |
solulu Pro
Continue this lesson with Pro
Inside: 4 sections · 1 video · quiz.
- The 5 steps
- Example: Frog Jump
- 2-D tables
- Save memory
Lifetime ₹1,999 ₹999 · Launch offer
Item 21 of 44 · updated 2026-10-13