Feel free to ask for help on this section if you get stuck. We'll be discussing a somewhat difficult subject and it may be helpful to have it explained in person.

If the user may be searching for the same number multiple times, it seems ridiculous to calculate the answer each time that they ask. Why don’t we remember the answer after it’s been calculated instead? Remembering previously calculated information is called memoization (not memorization) in computer science. It is a powerful technique that can be used to speed up programs that have redundant calculations.

Let’s implement a third block in our project that uses memoization to remember the location of numbers that have already been found. This block will be very similar to our the second block you built, the sorted number finder.

Memoized
We’ll use a list to keep track of the locations of numbers that we’ve found already: the index of each element in the list will be the number we’re looking for and the corresponding value will be the location where that number was found. If the value at a particular index is -1, that means that we haven’t looked for the number yet and if the value is 0 then that means that the number doesn't exist in the list. Here is an algorithm describing how the new block should progress using the new memoization list:
  1. Start off setting all of the slots in memory to -1 because we haven't found any numbers yet.
  2. Check the global list memory to determine if the number in question has already been found.
  3. If so, report the saved location. If not, we’ll have to calculate it.
  4. Find the number’s location using the sorted technique we’ve used in the past.
  5. Save the location of the number in the memory list so that we don't have to go through this pain again.

Each value will now be computed a maximum of one time. Now that’s fast!

Consider the following questions: