如何计算对数级数的平方和

时间:2013-10-03 03:32:30

标签: algorithm math big-o time-complexity

我有一个算法,我发现它的运行时复杂性遵循以下公式:

[log(1)]^2 + [log(2)]^2 + [log(3)]^2 + ....... + [log(n)]^2

日志的基础是2。

如何根据此公式计算Θ/Ο算法复杂度?

1 个答案:

答案 0 :(得分:2)

对于上限你可以推理similat log(n!)= O(nlog(n))

[log(1)]^2 + [log(2)]^2 + [log(3)]^2 + ....... + [log(n)]^2 < [log(n)]^2 + ... + [log(n)]^2
                                                            = n[log(n)]^2

[log(1)]^2 + [log(2)]^2 + [log(3)]^2 + ....... + [log(n)]^2  = O( n[log(n)]^2 )

为了证明下限,需要证明给定的和是&gt; = n [log(n)] ^ 2的常数倍

从总和

中删除前半部分的术语
[log(1)]^2 + [log(2)]^2 + [log(3)]^2 + ....... + [log(n)]^2 >= [log(n/2)]^2 + [log(n/2 + 1)]^2 + [log(3)]^2 + ....... + [log(n)]^2

用log(n / 2)^ 2替换每个术语

[log(1)]^2 + [log(2)]^2 + [log(3)]^2 + ....... + [log(n)]^2  >= (n/2) * [log(n/2)]^2

下限= (n/2) * [log(n) - 1] ^ 2

我们可以证明log(n) - 1 >= (1/2) * log(n)

因此下限= (n/8) * [log(n)] ^ 2和上限= n * [log(n)] ^ 2

所以Θ([log(1)]^2 + [log(2)]^2 + [log(3)]^2 + ....... + [log(n)]^2) = n * [log(n)] ^ 2