The answer is Theta(n)
. To prove something is Theta(n)
, you have to show it is Omega(n)
and O(n)
. Omega(n)
in this case is obvious because T(n)>=n
. To show that T(n)=O(n)
, first
- Pick a large finite value
N
such thatlog(n)^2 < n/100
for alln>N
. This is possible becauselog(n)^2=o(n)
. - Pick a constant
C>100
such thatT(n)<Cn
for alln<=N
. This is possible due to the fact thatN
is finite.
We will show inductively that T(n)<Cn
for all n>N
. Since log(n)<n
, by the induction hypothesis, we have:
T(n) < n + log(n) C log(n)
= n + C log(n)^2
< n + (C/100) n
= C * (1/100 + 1/C) * n
< C/50 * n
< C*n
In fact, for this function it is even possible to show that T(n) = n + o(n)
using a similar argument.