Calculating the Recurrence Relation T(n)=T(n-1)+logn

天大地大妈咪最大 提交于 2019-12-03 16:35:25

This expands out to log (n!). You can see this because

T(n) = T(n - 1) + log n

= T(n - 2) + log (n - 1) + log n

= T(n - 3) + log (n - 2) + log (n - 1) + log n

= ...

= T(0) + log 1 + log 2 + ... + log (n - 1) + log n

= T(0) + log n!

The exact answer depends on what T(0) is, but this is Θ(log n!) for any fixed constant value of T(0).

A note - using Stirling's approximation, Θ(log n!) = Θ(n log n). That might help you relate this back to existing complexity classes.

Hope this helps!

Stirling's formula is not needed to get the big-Theta bound. It's O(n log n) because it's a sum of at most n terms each at most log n. It's Omega(n log n) because it's a sum of at least n/2 terms each at least log (n/2) = log n - 1.

Yes, this is a linear recurrence of the first order. It can be solved exactly. If your initial value is $T(1) = 0$, you do get $T(n) = \log n!$. You can approximate $\log n!$ (see Stirling's formula): $$ \ln n! = n \ln n - n + \frac{1}{2} \ln \pí n + O(\ln n) $$

[Need LaTeX here!!]

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!