Computational complexity of Fibonacci Sequence

后端 未结 11 1455
慢半拍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:54

    Well, according to me to it is O(2^n) as in this function only recursion is taking the considerable time (divide and conquer). We see that, the above function will continue in a tree until the leaves are approaches when we reach to the level F(n-(n-1)) i.e. F(1). So, here when we jot down the time complexity encountered at each depth of tree, the summation series is:

    1+2+4+.......(n-1)
    = 1((2^n)-1)/(2-1)
    =2^n -1
    

    that is order of 2^n [ O(2^n) ].

提交回复
热议问题