Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Closed form O(1) solution? Using Binet's formula, if that's what you mean, is not O(1), for a number of reasons. Firstly, exponentiation is not constant-time. Secondly, how are you going to do it to the necessary precision? Are you really going to use some sort of floating-point number for this? Of course, you could use an exact representation, using a pair of integers (or rational numbers, depending on what basis you use)... but that will be essentially the same as the usual matrix solution.

Remember, the n'th Fibonacci number has a number of bits linear in n, and you need at least the time to write all those bits out. That can't be done in O(1), no matter how you do the computation!



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: