T(n) = 25T(n/5)+n^2的时间复杂度 计算方法

对于T(n) = a*T(n/b)+c*n^k;T(1) = c 这样的递归关系,有这样的结论:

if (a > b^k)   T(n) = O(n^(logb(a)));logb(a)b为底a的对数
if (a = b^k)   T(n) = O(n^k*logn); 
if (a < b^k)   T(n) = O(n^k);

a=25; b = 5 ; k=2

a==b^k T(n)=O(n^k*logn)=O(n^2*logn)

T(n) = 25T(n/5)+n^2

= 25(25T(n/25)+n^2/25)+n^2
= 625T(n/25)+n^2+n^2 = 625T(n/25) + 2n^2
= 25^2 * T( n/ ( 5^2 ) ) + 2 * n*n
= 625(25T(n/125)+n^2/625) + 2n^2
= 625*25*T(n/125) + 3n^2
= 25^3 * T( n/ ( 5^3 ) ) + 3 * n*n
= ....
= 25 ^ x * T( n / 5^x ) + x * n^2

T(n) = 25T(n/5)+n^2
T(0) = 25T(0) + n^2 ==> T(0) = 0
T(1) = 25T(0)+n^2 ==> T(1) = 1

x = lg 5 n

  25 ^ x * T( n / 5^x ) + x * n^2
= n^2 * 1 + lg 5 n * n^2
= n^2*(lgn)

展开阅读全文

没有更多推荐了,返回首页