Fast Fibonacci Algorithms (2015)
nayuki.io
nayuki.io
It's a neat illustration of asymptotic running times.
http://kukuruku.co/hub/algorithms/automatic-algorithms-optim...
Edit: Someone's implementation: http://ideone.com/NWQe38
Edit: constant time -> log time
[1] Schönhage-Strassen multiplication, one of many bignum multiplication algorithms with sub-quadratic complexity. Other algorithms in common use have worse asymptotic performance.
It's also worth noting that since the Fibonacci sequence grows exponentially, the number of digits is the result will be linear in n. Therefore, the memory requirement is actually O(n), and writing the result to the screen will be O(n).
Right; as you sketch out, there's some constants that disappear into the O() notation.
also the laddering scheme used for the 'exponentiation' can be in different forms, the left-to-right or right-to-left form or even a Montgomery ladder...
i seemed to recall there is a 'fastest known' method for generating fibonacci or lucas numbers... but google is not helping me.
pretty sure i had seen it in this book: https://www.amazon.co.uk/Prime-Numbers-Computational-Carl-Po... i'll have to check when i have access to it next. :)
[1]: http://grepcode.com/file/repository.grepcode.com/java/root/j...
[2]:https://en.wikipedia.org/wiki/Toom%E2%80%93Cook_multiplicati...
Unless there is some kind of quantum computer algorithm that fits this problem well.
I still think this is a really cool technique though, even if it only works in "math land." http://bit.ly/fib_using_eigenvals
It's all contained in the sample pages http://matrixeditions.com/VC5.Chap2.219-221.pdf
However, even though the formula is O(1), the runtime of the algorithm might be larger.
Simply because a standard 64bit integer might be too small. And the BigNum implementation needs more time to multiply all the bits.
there are more advanced formulas in this article of Curtis McMullen http://www.math.harvard.edu/~ctm/papers/home/text/papers/cf/...