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

前端 未结 6 1092
悲&欢浪女
悲&欢浪女 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:19

    With the recursive algo, you have approximately 2^N operations (additions) for fibonacci (N). Then it is O(2^N).

    With a cache (memoization), you have approximately N operations, then it is O(N).

    Algorithms with complexity O(N log N) are often a conjunction of iterate over every item (O(N)) , split recurse, and merge ... Split by 2 => you do log N recursions.

提交回复
热议问题