Improving Performance Using Memoization

I once attended a bird show where a performer challenged a teenager to compete against a parrot in arithmetic. To the chagrin of the young fellow and the amusement of the viewers, the parrot swiftly replied to “what’s 200 times 50?" After the parrot aced the next few questions, the performer revealed the secret—the parrot simply repeated memorized answers to scripted questions. In this section we’ll use a similar technique, but rather than calling it memorization, we’ll term it memoization, continuing the tradition in our field of giving odd names to concepts.

In the previous section you learned a technique to make recursive calls memory-efficient. Recursion in essence is a way to solve a problem using ...

Get Programming Groovy 2 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.