memoisation

Caching a function's results by its arguments so that repeated calls return the stored answer instead of recomputing it.

In more detail

Memoisation is top-down dynamic programming: keep the natural recursive code and add a cache. In Python, decorating the function with functools.lru_cache does it in one line. It still uses the call stack, so very deep recursion can hit the recursion limit.

Related terms

Taught in

References