-1

Given the recurrence:
A(n) = A(n-1) + n*log(n).
How do I find the time complexity of A(n)?

xenteros
  • 15,586
  • 12
  • 56
  • 91
awareeye
  • 3,051
  • 3
  • 22
  • 22

2 Answers2

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)).

enter image description here

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

enter image description here

Now you have a very clear upper bound, so the is there for free (O(nlog(n!))). In case you're looking for a you need to struggle a bit longer.

xenteros
  • 15,586
  • 12
  • 56
  • 91
3
  1. Let A(0)=c. Find A(n) as a function of n and c, defined by sum.
  2. How many terms are in the sum?
  3. What is a minimal value of the sum? Try to find an estimation.
  4. What is a maximal value of the sum? Try to find an estimation.
  5. 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