This document discusses recursion and memoization. It introduces the Fibonacci numbers and the problem of tiling a corridor of length n. It shows the recursive definition of the number of tilings as C(n) = C(n-1) + C(n-2), with base cases C(1)=1 and C(2)=2. It notes that directly implementing this recursion leads to redundant computations. Memoization is proposed as a technique to store computed values in a table to avoid recomputing them, making the algorithm more efficient.
29. Simply store the values when you compute them.
Memoization - The Basic Idea
30. Simply store the values when you compute them.
Before delving into a recursive rabbit hole,
check if the value is already stored somewhere.
Memoization - The Basic Idea
31. Simply store the values when you compute them.
Before delving into a recursive rabbit hole,
check if the value is already stored somewhere.
Get into recursion on a need-to basis.
Memoization - The Basic Idea
32. Simply store the values when you compute them.
Before delving into a recursive rabbit hole,
check if the value is already stored somewhere.
Get into recursion on a need-to basis.
We’re doing “actual work” for only n distinct subproblems.
The rest is only table lookups.
Memoization - The Basic Idea