Memoization & the Slot Filler
In short: some recursions ask the same question over and over —
overlapping subproblems — and when the answer to a bigger question is
built from answers to smaller ones — optimal substructure — that's a
dynamic programming problem. Memoization keeps a notebook (a dict, or
Python's @functools.cache) of every question already answered: check it
before computing, write the answer after. The recursion is unchanged; only
the repeated work disappears, usually turning exponential time into linear
or polynomial time.

Counting fib the slow way
Tunebox Radio fills gaps with station idents, and the scheduling screen shows how many different ident sequences could fill each gap. The obvious recursive count answers instantly for a 10-minute gap and freezes the app at 40. Fibonacci is the smallest program with the same disease:
21,891 calls to work out one number. Here is why: fib(3) is solved twice
and fib(2) three times inside fib(5) alone, and every level roughly
doubles the repeats:
A memo answers each repeated question from its notes, so whole subtrees of calls disappear.
Plain recursion makes all 15 of these calls, yet there are only 6 different questions. Binary tree, 15 nodes, height 5. At node fib(5).
calls = 0
def fib(n):
global calls
calls += 1
if n < 2:
return n
return fib(n - 1) + fib(n - 2)
fib(5)
print(calls)The cost if you don't fix it: the running time grows like φⁿ ≈
1.618ⁿ. fib(40) makes about 331 million calls.