Posted on 2010-05-20 11:11
千张 阅读(1539)
评论(0) 编辑 收藏 引用 所属分类:
程序员笔试宝典
对于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);
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)