简体   繁体   English

如何解决此递归关系:T(n)= 4 * T(sqrt(n))+ n

[英]How to solve this recurrence relation: T(n) = 4*T(sqrt(n)) + n

I know how to solve the recurrence relations using Master Method. 我知道如何使用主方法解决递归关系。 Also I'm aware of how to solve the recurrences below: 我也知道如何解决以下重复问题:

T(n) = sqrt(n)*T(sqrt(n)) + n T(n)= sqrt(n)* T(sqrt(n))+ n

T(n) = 2*T(sqrt(n)) + lg(n) T(n)= 2 * T(sqrt(n))+ lg(n)

In the above two recurrences there is same amount of work at each level of the recursion tree. 在以上两个重复中,递归树的每个级别上的工作量相同。 And there are a total of log log n levels in the recursion tree. 递归树中总共有log log n个级别。

I'm having trouble in solving this one: T(n) = 4*T(sqrt(n)) + n 我在解决这一问题时遇到了麻烦:T(n)= 4 * T(sqrt(n))+ n

EDIT: Here n is a power of 2 编辑:这里n是2的幂

Suppose that n = 2^k. 假设n = 2 ^ k。 We have T(2^k) = 4*T(2^(k/2)) + 2^k. 我们有T(2 ^ k)= 4 * T(2 ^(k / 2))+ 2 ^ k。 Let S(k) = T(2^k). 令S(k)= T(2 ^ k)。 We have S(k) = 4S(k/2) + 2^k. 我们有S(k)= 4S(k / 2)+ 2 ^ k。 By using Mater Theorem, we get S(k) = O(2^k). 通过使用Mater定理,我们得到S(k)= O(2 ^ k)。 Since S(k) = O(2^k) and S(k) = T(2^k), T(2^k) = O(2^k) which implies T(n) = O(n). 由于S(k)= O(2 ^ k)并且S(k)= T(2 ^ k),因此T(2 ^ k)= O(2 ^ k)这意味着T(n)= O(n)。

I'm having trouble in solving this one: T(n) = 4*T(sqrt(n)) + n 我在解决这一问题时遇到了麻烦:T(n)= 4 * T(sqrt(n))+ n

EDIT: Here n is a power of 2 编辑:这里n是2的幂

This edit is important. 此编辑很重要。 So lets say that the recurrence stops at 2. 因此,可以说递归在2处停止。

So the question now is how deep the recursion tree is. 因此,现在的问题是递归树的深度。 Well, that is the number of times that you can take the square root of n before n gets sufficiently small (say, less than 2). 好吧,这是您可以在n变得足够小(例如,小于2)之前取n的平方根的次数。 If we write 如果我们写

n = 2 lg n n = 2 lg n

then on each recursive call n will have its square root taken. 那么在每个递归调用中n都会取其平方根。 This is equivalent to halving the above exponent, so after k iterations we have that 这等效于将上述指数减半,因此经过k次迭代,我们得到了

n 1/(2 k ) = 2 lg n/(2 k ) n 1 /(2 k = 2 lg n /(2 k

We want to stop when this is less than 2, giving 我们想在小于2时停止

2 lg n/(2 k ) = 2 2 lg n /(2 k = 2

lg n/(2 k ) = 1 lg n /(2 k )= 1

lg n = 2 k lg n = 2 k

lg lg n = k lg lg n = k

So after lg lg n iterations of square rooting the recursion stops. 因此,在平方根的所有迭代之后,递归停止。 ( source ) 来源

For each recursion we will have 4 new branches, the total of branches is 4 ^ (depth of the tree) therefore 4^(lg lg n) . 对于每次递归,我们将有4个新分支,分支的总数为4 ^(树的深度),因此为4^(lg lg n)

EDIT : 编辑

在此处输入图片说明

Source 资源

   T(n) = 4 T(sqrt(n)) + n
   4 [ 4 T(sqrt(sqrt(n) + n ] + n
   4^k * T(n^(1/2^k)) +kn because n is power of 2.
   4^k * T(2^(L/2^k)) +kn   [  Let n = 2^L , L= logn]
   4^k * T(2) +kn   [  Let L = 2^k,  k = logL = log log n]
   2^2k * c +kn
   L^2 * c + nloglogn 
   logn^2 * c + nloglogn
   = O(nloglogn)
T(n) = 4T(√n) + n 
suppose that (n = 2^m) . so we have :
T(2^m) = 4T(2^(m/2)) + (2^m)
now let name T(2^m) as S(m):
S(m) = 4S(m/2) + m . now with master Method we can solve this relation, and the answer is :
S(m) = Θ(m^2) 
now we step back to T(2^m):
T(2^m) = Θ((2^m)^2)
now we need m to solve our problem and we can get it from the second line and we have :
n = 2^m   =>   m=lgn 
and the problem solved .
T(n) = Θ((2^lgn)^2)
T(n) = Θ(n^2)

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

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