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

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

    To address the core of the question, that is "why Fibonacci and not Mergesort", you should focus on this crucial difference:

    • The tree you get from Mergesort has N elements for each level, and there are log(n) levels.
    • The tree you get from Fibonacci has N levels because of the presence of F(n-1) in the formula for F(N), and the number of elements for each level can vary greatly: it can be very low (near the root, or near the lowest leaves) or very high. This, of course, is because of repeated computation of the same values.

    To see what I mean by "repeated computation", look at the tree for the computation of F(6):


    Fibonacci tree picture from: http://composingprograms.com/pages/28-efficiency.html

    How many times do you see F(3) being computed?

提交回复
热议问题