you have done the fibonacci series with 1) recursion with O(n-1)+O(n); 2) linear dynamic programming c=a+b; a=b; b=c; in looping to n with O(n); 3) with matrix exponential O(log n); so we are intesesting how the order log n is justified with matrix exponential; here are the observations comeoncodeon-fr0ddy related to it i concluded thathere is the code given explore it
- if we represent the fibonacci as the matrix than
here first element of fibonacci series is 1 the matrix fib[0][0]
- if we have to find out fibonacci series at n then fib[]n
- n can be odd or even.
- if it is even n= 2 * k "k" be any integer then the matrix next element is found by repeated squaring i.e.
- else multiply by its previous matrix i.e. fib[]n=fib[] * fib[]n-1
- and loop till goal state is achieved
you can also test its speed by testing cases at fibonacci(log n) code see how fast it is running from your recursive fibonacci.

Don't exaagerate. It is perfectly understandable. Even Americans speak a dialect intelligible to the British (English, Scottish and Irish).
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteComplexity of recursive solution (without memoization) is exponential, not "O(n-1) + O(n)" which would be O(n).
ReplyDelete