solulubeta
Sign in
Recursion & Memo / From recursion to memoization
03.02 · Lesson

From Memo to Table

The same DP as a loop instead of recursion: same array, base cases first, loop so that what you need is already filled, copy the recurrence. Then save memory with two variables.

11 min 1 video Quiz Pro

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

StepDo
1Same array, same size as the memo
2Write the base-case answers into it
3Loop so that the values you need are already filled
4Copy the recurrence, with f(x) replaced by dp[x]
5The 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
Mark this as done when you are finished.

Item 21 of 44 · updated 2026-10-13