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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.