The Naïve Approach

The formal definition of the Fibonacci sequence looks something like this:

F(n)={0 n=01 n=1F(n1)+F(n2)n2 F(n) = \begin{cases} 0\ & n = 0 \\ 1\ & n = 1 \\ F(n-1) + F(n-2) & n \ge 2 \end{cases}

Let's just translate this directly into computer code and see how that goes.

The Naïve Approach

The formal definition of the Fibonacci sequence looks something like this:

F(n)={0 n=01 n=1F(n1)+F(n2)n2 F(n) = \begin{cases} 0\ & n = 0 \\ 1\ & n = 1 \\ F(n-1) + F(n-2) & n \ge 2 \end{cases}

Let's just translate this directly into computer code and see how that goes.