Most Fibonnacci (n) values โโare calculated twice.
For example, Fibonacci (5) calls Fibonacci (4) and Fibonacci (3).
The fact that Fibonacci (4), in turn, causes Fibonacci (3) and Fibonacci (2).
See how Fibonacci (3) is called twice in this example? That will help memoize, but the algorithm, although interesting and recursive, is inefficient. It would be preferable to use a more efficient algorithm than remembering an inefficient one.
source share