Todos os livros

Profissional

Apps Sobre Coach Entrar Começar a ler

Computer Science · Glossário

O que é Memoisation?

Definition 28.2 High School Computer Science · Capítulo 28 — Dynamic Programming

Memoisation is the recording of a function’s results in a table, usually a dictionary from arguments to results: the function looks the arguments up before computing, and stores the result before returning.

The 9 calls of the memoised fib(5), against 15 for the naive one. The first call on each value computes it, going down the left side; every later call on it finds it in the dictionary and returns at once, so the tree has no repeated subtree.
The 99 calls of the memoised fib(5), against 1515 for the naive one. The first call on each value computes it, going down the left side; every later call on it finds it in the dictionary and returns at once, so the tree has no repeated subtree.
Calls made by the two versions of fib(n), from figures/calls.py, with a scale that multiplies by 10 at each mark. The naive count is multiplied by about 1.6 at each step and passes 29 million at n = 35; the memoised count is 2n - 1, 69 at n = 35.
Calls made by the two versions of fib(n), from figures/calls.py, with a scale that multiplies by 1010 at each mark. The naive count is multiplied by about 1.61.6 at each step and passes 2929 million at n=35n = 35; the memoised count is 2n−12n - 1, 6969 at n=35n = 35.
Ler no capítulo →