Given the recurrence:
A(n) = A(n-1) + n*log(n)
.
How do I find the time complexity of A(n)
?
Asked
Active
Viewed 188 times
-1
-
1I cant see how this recurrence relation is terminating. – Luka Rahne Nov 07 '16 at 11:56
-
2@LukaRahne: Indeed. Presumably A(1) is the first term. – Bathsheba Nov 07 '16 at 11:57
-
@Shantanu did my answer solve your problem? Could you somehow respond? I'm open to give you more explanation if needed. – xenteros Nov 07 '16 at 12:54
-
@xenteros yes it does answer my question. I have marked it as the correct answer. Thanks very much! I understood the big-O part. How would you approach finding the tight bound (big-theta)? – awareeye Nov 07 '16 at 14:56
-
@LukeRahne sorry for not making that explicit in the question. It does terminate at A(1) – awareeye Nov 07 '16 at 14:56
2 Answers
6
A(n) = A(n-1) + nlog(n)
Look, your recurence says: take the previous value and add nlogn
to it.
So... assuming that A(1) = log(1) is the first element of the sequence: A(n) = SUM from i = 1 to n (ilog(i))
.
Why?
A(1) = log(1).
A(2) = log(1) + 2log(2).
A(3) = A(2) + 3log(3) = 1log(1) + 2log(2) + 3log(3).
.
.
.
A(n) = 1log(1) + 2log(2) + 3log(3) + ... + nlog(n)
This way of solving recursion can be always used when F(n) - F(n-1)
is a non recursive function. In our case it's nlogn
so it worked.
Similar rule can be used when F(n)/F(n-1)
is a non recursive function. Then we use PI instead of SIGMA.
If I were asked to give it an upper bound I would suggest to try the following:
log(n) + log(n) + log(n) + log(n) + ...
+ log(n-1) + log(n-1) + log(n-1) + ...
+ log(n-2) + log(n-2) + ...
.
.
.
so
Now you have a very clear upper bound, so the big-o is there for free (O(nlog(n!))
). In case you're looking for a big-theta you need to struggle a bit longer.

xenteros
- 15,586
- 12
- 56
- 91
-
-
Question was what is complexity for calculating recurrence relation, not what result is. – Luka Rahne Nov 07 '16 at 11:53
-
@xenteros oh yes I see, but it should be A(n) = ½ • n(n-1) • sum_{i=1}^n{log(i)} then. – ToxiCore Nov 07 '16 at 11:53
-
@ToxiCore if you find my answer satisfying feel free to mark it as solution – xenteros Nov 07 '16 at 12:11
-
@xenteros I find it very satisfying and interesting - sadly I am not the one who asked the question elseways I already would have done that :/ but you've got an upvote! – ToxiCore Nov 07 '16 at 12:20
-
@ToxiCore haha, suprising. Anyway, you made me to struggle a bit and build a better answer. – xenteros Nov 07 '16 at 12:22
-
3`O(N log N!)` is the same as `O(N^2 log N)`, via Stirling's approximation: https://en.wikipedia.org/wiki/Stirling%27s_approximation – Matt Timmermans Nov 07 '16 at 13:04
-
@xenteros do you happen to know how the big-theta (tight bound) can be found for this recurrence? Thanks! – awareeye Nov 07 '16 at 14:59
-
3
- Let A(0)=c. Find A(n) as a function of n and c, defined by sum.
- How many terms are in the sum?
- What is a minimal value of the sum? Try to find an estimation.
- What is a maximal value of the sum? Try to find an estimation.
- If you can estimate (3) and (4) such that they one of them is constant times bigger than other, are you done? Why?

user31264
- 6,557
- 3
- 26
- 40