Although the recursive implementation given above is elegant and close to the mathematical definition, it is not very practical. Calculating the nth fibonacci number requires calculating two smaller fibonacci numbers, which in turn require two additional recursive calls each, and so on until all branches reach 1. The iterative solution is faster, but still repeats a lot of calculations when computing successive fibonacci numbers. To remedy this, we can employ memoization to cache previous computations.
We first establish a memoization "cache", which stores previously computed fibonacci numbers. In this case we use an ArrayList, initialized with the first two fibonacci numbers, as the cache. Note that we have also moved from using ints to using Java's BigInteger class, which provides arbitrary-precision integers. As a result, the memoized implementation can also compute much larger fibonacci numbers than the previous solutions (although they too could have been implemented using BigIntegers.
=============== Ben 10 Games