Computational complexity of Fibonacci Sequence

后端 未结 11 1449
慢半拍i
慢半拍i 2020-11-21 10:27

I understand Big-O notation, but I don\'t know how to calculate it for many functions. In particular, I\'ve been trying to figure out the computational complexity of the nai

11条回答
  •  我在风中等你
    2020-11-21 10:29

    There's a very nice discussion of this specific problem over at MIT. On page 5, they make the point that, if you assume that an addition takes one computational unit, the time required to compute Fib(N) is very closely related to the result of Fib(N).

    As a result, you can skip directly to the very close approximation of the Fibonacci series:

    Fib(N) = (1/sqrt(5)) * 1.618^(N+1) (approximately)
    

    and say, therefore, that the worst case performance of the naive algorithm is

    O((1/sqrt(5)) * 1.618^(N+1)) = O(1.618^(N+1))
    

    PS: There is a discussion of the closed form expression of the Nth Fibonacci number over at Wikipedia if you'd like more information.

提交回复
热议问题