Speeding Up with Memoization
Quick, what’s 25 * 12?
Unless you have some superpowers, you’ll take some effort and time to arrive at the result of 300. Now, if I ask again what’s 25 * 12, right away, you’ll instantaneously snap back the response of 300. How did you get that good so fast? Well, you remembered the result, temporarily memorized it—or should we say you memoized it.
If you evaluated an expression or looked up some information recently, and if you need that again, you most likely use the details from your memory instead of repeating the task. But computers can do that kind of stuff a lot more efficiently than we can. Reusing the result of a computation, instead of repeating its evaluation, is a technique called memoization.
This is ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access