以√n为参数求解递归关系


18

考虑复发

T(n)=nT(n)+cn

对于n>2且具有一些正常数,并且。T 2 = 1cT(2)=1

我知道用于解决递归的Master定理,但是我不确定如何使用它来解决这种关系。您如何计算平方根参数?


5
主定理不适用于此处;n不能写成nb您还尝试了什么?
拉斐尔

@Raphael:我尝试了替换方法,但是似乎卡住了我应该选择替代的值。
搜寻者2012年

1
“重复几次,观察模式,猜测解决方案并证明它 ”怎么样?
拉斐尔

好吧,这是这种类型的初学者,也许这里的一些帮助将帮助我轻松地解决自然界未来的问题。
搜寻者2012年

自从您提到Master定理以来,我假设您需要解决这一关系的渐近边界,并且实际上并不需要闭合形式的表达式。下面给出了找到闭合形式表达式的一些好的解决方案,这也给出了渐近复杂性。但是,如果只需要渐近复杂度,则分析会更简单。看看这里了解如何寻找渐近复杂性,为您的问题比如一个漂亮直观的解决方案很好的解释。
Paresh 2012年

Answers:


9

我们将使用Raphael的建议并展开复发。在下面,所有对数均以2为底。

其中,βn是必须从平方根开始以n开始并达到2的次数。结果证明,βn=loglogn。你怎么看?考虑: n

T(n)=n1/2T(n1/2)+cn=n3/4T(n1/4)+n1/2cn1/2+cn=n7/8T(n1/8)+n3/4cn1/4+2cn=n15/16T(n1/16)+n7/8cn1/8+3cn=n2T(2)+cnβ(n).
β(n)β(n)=loglogn 因此,需要平方根才能达到2的次数是1的解。
n=2lognn1/2=212lognn1/4=214logn
,这是记录日志Ñ。因此,递归的解决方案是cnloglogn+112tlogn1loglogn。为了使此操作绝对严格,我们应该使用替换方法,并且要小心处理。有时间时,我将尝试将此计算结果添加到我的答案中。cnloglogn+12n

“您必须记录n次平方根 ” –可以期望初学者看到吗?另外,您的结果与Yuval的结果不符;只是渐近地打算?loglogn
拉斐尔

@Raphael:Yuval犯了一个错误,现在他已纠正。我将在答案中解释平方根。
彼得·

3
另一个想法看到,递归需要如下:通过采取平方根ñ你减半所需的二进制表示的数字ñ。因此,您的输入需要w = log n位,并且将每个递归级别的字长除以2。因此,您在log w = log log n步骤之后停止。O(loglogn)nnw=lognlogw=loglogn
A.Schulz

10

In your comment you mentioned that you tried substitution but got stuck. Here's a derivation that works. The motivation is that we'd like to get rid of the n multiplier on the right hand side, leaving us with something that looks like U(n)=U(n)+something. In this case, things work out very nicely:

T(n)=n T(n)+nso, dividing by n we getT(n)n=T(n)n+1and letting n=2m we haveT(2m)2m=T(2m/2)2m/2+1
Now let's simplify things even further, by changing to logs (since lgn=(1/2)lgn). Let
S(m)=T(2m)2mso our original recurrence becomesS(m)=S(m/2)+1
Aha! This is a well-known recurrence with solution
S(m)=Θ(lgm)
Returning to T(), we then have, with n=2m (and so m=lgn),
T(n)n=Θ(lglgn)
So T(n)=Θ(nlglgn).

6

If you write m=logn  you have T(m)=m2T(m2)+c2m .

Now you know the recursion tree has hight of order O(logm), and again it's not hard to see it's O(2m)  in each level, so total running time is in: O((logm)2m) , which concludes O(nloglogn)  for n.

In all when you see n or nab,a<b , is good to check logarithm.

P.S: Sure proof should include more details by I skipped them.


2

Let's follow Raphael's suggestion, for n=22k:

T(n)=T(22k)=22k1T(22k1)+c22k=22k1+2k2T(22k2)+c(22k+22k)==22k1+2k2++20T(220)+c(22k+22k++22k)=22k1+ck22k=(cloglogn+1/2)n.

Edit: Thanks Peter Shor for the correction!


How did you come up with 22k? Note for OP: "" is not a proof, you'll have to provide that still (usually by induction).
Raphael

@Raphael: It's nearly a proof. You just need to show that it's also correct for numbers not of the form 22k.
Peter Shor

Actually, the recurrence is only well-defined for numbers of the form 22k, since otherwise, at some point n wouldn't be an integer, and you'll never reach the base case T(2).
Yuval Filmus

1
If this recurrence actually came from an algorithm, it would probably really be something more like T(n)=nT(n)+cn.
Peter Shor

1

Unravel the recurrence once as follows:

T(n)=n T(n)+n=n1/2(n1/4 T(n1/4)+n1/2)+n=n11/4 T(n1/4)+2n.

Continuing the unraveling for k steps, we have that:

T(n)=n11/2kT(n1/2k)+kn.

These steps will continue until the base case of n1/2k=2. Solving for k we have:

n1/2k=2logn=2kk=loglogn.

Substituting k=loglogn into the unraveled recurrence, we have

T(n)=n2T(2)+nloglogn.

2
Could you rewrite your picture to MathJax? We discourage images with text as the answers.
Evil

1
@PKG it seems like your edit is slightly different and also you explain steps, maybe you could answer on your own.
Evil
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.