Adobe Interview Question
Software Engineer / DevelopersCountry: India
Interview Type: Written Test
It is log 1 + log 2 + ... + log n which is Theta(n log n).
A more precise value is given by Stirlings formula.
We have sum of logarithms.
log 1 + log 2 + .... + log N
Using product rule from wiki page:
en.wikipedia.org/wiki/Logarithm
we have log (1*2*....*n) = log n!
According to Ramanujan formula from
en.wikipedia.org/wiki/Factorial
log n! = n * log n - n + ....
So, O(log n!) = O(n*log n)
That's if you want to get all fancy up in here. I can show it's NlogN much more simply:
_
log 1 + log 2 + ... + log N < log N + ... +log N = NlogN (bound from above)
_
log 1 + log 2 + .. + log N > log N/2 + log (N/2+1) + ... + log N > (N/2) * log(N/2) = (N/2) (logN - log2) = O(NlogN) (bound from below)
Assuming j is an integer O(nlogn)
- NewCoderInTown April 19, 2012