Search This Blog

Playing with time complexity: Fibonacci Numbers

Famous Fibonacci sequence was defined by mathematician Leonardo Fibonacci during 15th century.

This can be defined mathematically as above.

Exponential Time algorithm

The above expression itself gives us the idea of evaluating Fibonacci values by using recursion. Well, it works but takes so much of memory that the calculation of larger Fibonacci values is merely impossible.

In this method the matrix relationship among Fibonacci numbers are used.

This is derived through simple arithmetic, which is clearly visible from first two steps and raised to a power by using the pattern derived.

Further this can be simplified by using matrices and eigen values, which will be discussed in a later log post.

A formula?
The above formula leaves us with a simple calculation. But in here the calculation of power, which involves multiplication is expensive for a computer. Thus the time complexity if O(M(n) log n) where M(n) is the time complexity in multiplying 2 n bit numbers.