While reading an algorithms book, I learned that minor optimizations and choosing right algorithm can improve the code performance drastically. In this post we will see how this is happening.
Consider the following trivial code to calculate a Fibonacci value of a number using recursion.
int fibonacci(int num)
{
if (num <= 1)
return num;
else
return fibonacci(num - 1) + fibonacci(num - 2);
}
[/sourcecode]
Here is how this code executes for fibonacci(5)
. Continue reading