This is however a stupid thing to do from a computational perspective, because simply computing the matrix power is cheaper. This also holds for fibonacci numbers.
O(1) exponential implementations do not exist, for the simple reason that the output is already O(n) bits long.
Using Binets formula for calculating fibonacci numbers is stupid because you need to use arbitrary precision arithmetic. How many digits of precision suffice? Unknown. If you use floating point your algorithm will certainly already fail for the 100th fibonacci number.
18
u/angch Oct 03 '11
Or just use Binet's Fibonacci Number Formula. O(1), if you have decent exponential implementation.