{love to code?}

September 17, 2009

How small code optimizations can improve the performance and storage requirements

Filed under: Algorithms — navaneethkn @ 9:16 AM
Tags: ,

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);
}

Here is how this code executes for fibonacci(5). (more...)

Blog at WordPress.com.