求解递推式 T(n) = 2T(n/2) + n^4
我正在使用 MIT 课件和 CLRS 书籍算法简介进行学习。
我目前正在尝试解决递归问题(来自第 107 页)
T(n) = 2T(n/2) + n4
如果我制作一个递归树,我得到:
0级:n4
级别 1 2(n/2)4
2级4(n/4)4
3级8(n/8)4
树有 lg(n) 个级别。因此我认为复发应该是
T(n) = θ(n4 lg n)
但是,如果我使用主定理,我会得到
T(n) = θ(n4)
显然这两个都不正确。哪一个是正确的?我的推理哪里出了问题?
I am studying using the MIT Courseware and the CLRS book Introduction to Algorithms.
I am currently trying to solve the recurrence (from page 107)
T(n) = 2T(n/2) + n4
If I make a recurrence tree, I get:
Level 0: n4
Level 1 2(n/2)4
Level 2 4(n/4)4
Level 3 8(n/8)4
The tree has lg(n) levels. Therefore I think that the recurrence should be
T(n) = Θ(n4 lg n)
But, If I use the master theorem, I get that
T(n) = Θ(n4)
Clearly both of these can't be right. Which one is correct? And where did I go wrong with my reasoning?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
第二个看起来是正确的。请注意,您的递归树看起来像
但 2(n/2)4 ≠ n4,因为 (n/2)4 = n4 / 16,所以 2(n/2)4 = n4< /sup>/8。事实上,如果你计算一下数学,你就会发现在级别 i 所做的工作由下式给出
所以我们得到 (1 + 1/8 + 1/64 + 1/512 + ... ) n4< /sup>,可以显示小于 2n4。所以你的函数是 θ(n4)。
The second one looks correct. Notice that your recurrence tree looks like
But 2(n/2)4 ≠ n4, because (n/2)4 = n4 / 16, and so 2(n/2)4 = n4/8. In fact, if you work out the math, you get that the work being done at level i is given by
So we get (1 + 1/8 + 1/64 + 1/512 + ... ) n4, which can be shown to be less than 2n4. So your function is Θ(n4).
通过递归,它是 θ(n^4),
它是 θ(n^4)
With recursion it is Θ(n^4)
it is Θ(n^4)
这里可以直接使用主定理。
该方程适合主定理的情况 1,其中 log (a) 底 b
f(n)
a:重复次数
b : 子部分的数量
log a base b = log 2 base 2 = 1
n^4
因此根据马斯特斯定理,
T(n) = theta(f(n)) = theta(n^4)
You can use the master theorem here directly.
This equation fits in case 1 of master theorem where
log (a) base b < f( n)
a : Number of recurrence
b : Number of subparts
log a base b = log 2 base 2 = 1 < n^4
Therefore by masters theorem,
T(n) = theta(f(n)) = theta(n^4)
根据主定理
a=2, b=2, f(n)=n^4
第一步 - 计算 n^(log a to base b) => n(以 2 为底的 log 2) = n*1 = n
第二步-是否f(n)>?第一步结果=> n^4> n =>是的
这意味着使用主定理的情况 3。
第三步 - 检查正则条件
是的,正则条件满足,所以我们的解决方案必须满足。
By Master Theorem
a=2, b=2, f(n)=n^4
First step - Calculate n^(log a to base b) => n(log 2 to base 2) = n*1 = n
Second Step - Is f(n)> First step result => n^4> n => YES
This means use Case 3 of Master Theorem.
Third step - Check Regularity Condition
Yes, Regularity condition is met, so our solution must be.