简体   繁体   English

如何解决下面的递归关系?

[英]How to solving below recurrence relation?

This question came in the examination and I don't know how to do it can anyone help me or give some hint. 这个问题是考试中出现的,我不知道该怎么做,谁能帮助我或给我提示。 I think the master's method is not applicable here? 我认为大师的方法不适用于这里吗? Please help. 请帮忙。

T(n)=T(n/2)+ θ(logn) T(n)= T(n / 2)+θ(logn)

Assuming n is a power of 2 , say n = 2^k , and for simplicity, let's say T(n) = T(n/2) + lg(n) where lg is logarithm base 2 , and T(1) = lg(1) = 0 . 假设n2的幂,假设n = 2^k ,为简单起见,假设T(n) = T(n/2) + lg(n) ,其中lg是对数以2为底,而T(1) = lg(1) = 0

T(n) = lg(n) + lg(n/2) + lg(n/4) + ... + lg(1)
     = lg(2^k) + lg(2^{k-1}) + ... + lg(2^0)
     = k.lg(2) + (k-1)lg(2) + ... + 0.lg(2)
     = (k + (k-1) + ... + 0) lg(2)
     = k(k+1)/2
     = lg(n)(lg(n)+1)/2
     = Theta(lg(n)^2).

For n not a power of 2 , one can note that T is an increasing function, and so T(2^k) <= T(n) <= T(2^{k+1}) where k = floor(lg(n)) . 对于n不是2的幂,可以注意到T是一个递增函数,因此T(2^k) <= T(n) <= T(2^{k+1})其中k = floor(lg(n)) From the exact result above, we get 从上面的确切结果,我们得到

k(k+1)/2 <= T(n) <= (k+1)(k+2)/2

and so 所以

T(n) = Theta(floor(lg(n))^2) = Theta(lg(n)^2)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM