recursion - Calculating the Recurrence Relation T(n)=T(n-1)+logn -
we solve recurrence relation through repeating substitution:
t(n)=t(n-1)+logn
i started substitution , got following.
t(n)=t(n-2)+log(n)+log(n-1)
by logarithm product rule, log(mn)=logm+logn,
t(n)=t(n-2)+log[n*(n-1)]
continuing this, get
t(n)=t(n-k)+log[n*(n-1)*...*(n-k)]
we know base case t(1), n-1=k -> k=n+1, , substituting in get
t(n)=t(1)+log[n*(n-1)*...*1]
clearly n*(n-1)*...*1 = n! so,
t(n)=t(1)+log(n!)
i not know how solve beyond point. answer o(log(n!))? have read other explanations saying Θ(nlogn) , follows o(nlogn) , Ω(nlogn) upper , lower bounds respectively.
this expands out log (n!). can see 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 t(0) is, θ(log n!) fixed constant value of t(0).
a note - using stirling's approximation, θ(log n!) = θ(n log n). might relate existing complexity classes.
hope helps!
Comments
Post a Comment