The problem with using the Fibonacci Sequence as the opening example is that everyone knows how to generate that so recursion would seem an odd approach from the start. Using a different example to independently construct the recurrence relation combinatorically makes both the recursive and iterative approaches seem credible – the solved solution too, for that matter. This better makes the point that an apparently reasonable algorithm in theory might not be in practice.

]]>int f (int n) {

if (n < 3) { return n; }

else if ( cacheContainsResultFor (n) ) { return resultFromCacheFor (n); }

else { int result = f(n-1) + f(n-2); storeInCache (result); return result; }

}

I'm pretty sure that in the long run this performs better than any of the other solutions (despite consuming more resources). This also makes me think about the value of writing down stuff 😛

Sorry if this is already discussed in another post.

]]>You may also wish to mention that the recurrence relation that you posted above uses (1 + sqrt(5))/2, which also happens to be the golden ratio, another interesting point.

In any case, I would definitely recommend other readers to check out SICP by Abelson and Sussman, because it is an incredible book which covers these kinds of methods (and far more), and is probably the best place to start off computer science.

]]>So, I shared your blog with my brother, he can understand the rest of the context better than me 🙂 ]]>