January 2020
Intermediate to advanced
532 pages
13h 31m
English
In functional programming, recursion is a common technique for computation. Sometimes, we may fall into a performance pitfall unknowingly. A classic example is the generation of a Fibonacci sequence, which is defined as follows:

It works well functionally but it is not very efficient. Why? It is because the function is recursively defined, and the same function is called multiple times with the same arguments. Let's take a look at the computation graph when finding the sixth Fibonacci number, where each f(n) node represents a call to the fib function:
As you can see, the function is called many times, especially ...
Read now
Unlock full access