简体   繁体   English

递归复杂度T(n)=T(n/2)+T(n/2)+n^2?

[英]Complexity of the recurrence T(n)=T(n/2)+T(n/2)+n^2?

In accord to Master Theorem this recurrece is θ(n^2), but if we solve this with tree recurrence the solution is θ(n^2*logn).根据主定理,这个递归是 θ(n^2),但是如果我们用树递归来解决这个问题,那么解决方案是 θ(n^2*logn)。 Am I doing something wrong?难道我做错了什么?

If the recurrence relation is T(n) = 2T(n/2) + n^2, then you're in the third case of the master theorem, and the regularity condition applies, so T(n) = Theta(n^2).如果递归关系是 T(n) = 2T(n/2) + n^2,那么你是主定理的第三种情况,并且正则性条件适用,所以 T(n) = Theta(n^ 2)。 [c_crit is log_2(2) = 1, n^2 = Omega(n), 2(n/2)^2 = (n^2)/2 (so k<1, specifically k=1/2)] [c_crit 是 log_2(2) = 1, n^2 = Omega(n), 2(n/2)^2 = (n^2)/2 (所以 k<1, 特别是 k=1/2)]

If you expand out the recurrence relation by hand, then you get:如果你手动展开递归关系,那么你会得到:

T(n) = n^2 + 2(n/2)^2 + 4(n/4)^2 + 8(n/8)^2 + ...
     = n^2 ( 1 + 1/2 + 1/4 + 1/8 + ...)
     <= 2n^2

So this method too gives you T(n) = Theta(n^2).所以这个方法也给你 T(n) = Theta(n^2)。

The method of inputting the recurrence relation into Wolfram Alpha and seeing what it says gives T(n) ~ 2n^2, so again Theta(n^2). 将递归关系输入到 Wolfram Alpha 并查看它所说的方法给出了 T(n) ~ 2n^2,所以又是 Theta(n^2)。

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

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