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)

 

    原文作者:爱也玲珑
    原文地址: https://www.cnblogs.com/aiyelinglong/archive/2012/10/05/2712372.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞

发表评论

电子邮件地址不会被公开。 必填项已用*标注