首页 > 代码库 > Fibonacci 引出的关于递归时间复杂度

Fibonacci 引出的关于递归时间复杂度

Finonacci 

T(N) = T(N-1) + T(N-2);

>= 2T(N-2)  =  O(2^(N/2))

 

Memorized Dp algorithm 

//1,1,2,3,5,8.....Memo = {}fib(n):   if n in memo, return memo{n}   if n<=2: f =1   else: f = fib(n-1) + fib(n-2)   memo[n] = f   return f.

constant time.

memoized calls cost O(1)

nonmeoized calls cost O(n)

Fibonacci 引出的关于递归时间复杂度