Why is the complexity of computing the Fibonacci series 2^n and not n^2?

后端 未结 9 1829
深忆病人
深忆病人 2020-11-29 05:31

I am trying to find complexity of Fibonacci series using a recursion tree and concluded height of tree = O(n) worst case, cost of each level = cn,

9条回答
  •  渐次进展
    2020-11-29 06:04

    t(n)=t(n-1)+t(n-2) which can be solved through tree method:

                                      t(n-1)  +  t(n-2)        2^1=2
                                       |         |  
                                t(n-2)+t(n-3)  t(n-3)+t(n-4)   2^2=4  
                                    .               .          2^3=8
                                    .               .           .
                                    .               .           .
    

    similarly for the last level . . 2^n
    it will make total time complexity=>2+4+8+.....2^n after solving the above gp we will get time complexity as O(2^n)

提交回复
热议问题