
Figure 1. A tree showing the branching, exponential nature of recursive calls in fib1. The bottom row of the tree has calls; once the row grows to depth 20, there are 1,048,576 recursive calls.
One idea is to slavishly implement the recursive definition of Fn.
Here is the pseudocode of the resulting algorithm:

Let T(n) be the number of steps needed to
compute fib1(n); what can we say about this function? For starters, if n≤2, then the
procedure halts almost immediately, after just a couple of steps. Therefore,
T(n)≤2 for n≤1.
For larger values of n, there are two recursive calls of fib1, taking respective times T(n−1) and
T(n−2), plus three computer steps (checks on the value of n and a final addition).
Therefore,
T(n)=T(n−1)+T(n−2)+3 for n>1.
Compare this to the recurrence relation for Fn: we immediately see that T(n)≥Fn.
This is very bad news: the running time of the algorithm grows as fast as the Fibonacci
numbers themselves! T(n) is exponential in n, which implies that the algorithm is impractically slow
except for very small values of n.
Let’s try to understand why fib1 is so slow. Figure 1
shows the cascade of recursive
invocations triggered by a single call to fib1(n). Notice that many computations are repeated!
A more sensible scheme would store the intermediate results—the values F0,F1,…,Fn−1—as soon as they become known.

As with fib1,
the correctness of this algorithm is self-evident because it directly uses the
definition of Fn. How long does it take? The inner loop consists of a single computer step and
is executed n−1 times. Therefore the number of computer steps used by fib2 is linear in n.
From exponential we are down to polynomial, a huge breakthrough in running time. It is now
perfectly reasonable to compute F200 or even F200,000.
Source: Algorithms by Dasgupta, Papadimitriou, Vazirani. McGraw-Hill. 2006.
Visualization
To better feel the difference between polynomial and exponential time, try to compute F20
by using the following visualization by David Galles:
http://www.cs.usfca.edu/~galles/visualization/DPFib.html.
Selecting "Fibonacci Recursive" shows the enormous number of recursive calls that the program tries to
make in fib1. Stop the animation when you get tired of watching it, and instead click "Fibonacci Table" to
see just how much quicker using fib2 is. (Note however that a slightly different definition is used there:
F0=F1=1.)