Why is the Fibonacci Sequence Big O(2^n) instead of O(logn)?

前端 未结 6 1089
悲&欢浪女
悲&欢浪女 2021-01-31 06:29

I took discrete math (in which I learned about master theorem, Big Theta/Omega/O) a while ago and I seem to have forgotten the difference between O(logn) and O(2^n) (not in the

6条回答
  •  臣服心动
    2021-01-31 07:18

    To my understanding, the mistake in your reasoning is that using a recursive implementation to evaluate f(n) where f denotes the Fibonacci sequence, the input size is reduced by a factor of 2 (or some other factor), which is not the case. Each call (except for the 'base cases' 0 and 1) uses exactly 2 recursive calls, as there is no possibility to re-use previously calculated values. In the light of the presentation of the master theorem on Wikipedia, the recurrence

    f(n) = f (n-1) + f(n-2)
    

    is a case for which the master theorem cannot be applied.

提交回复
热议问题