Show That the Sum of log(i) from 1 to n Is O(n log n)
At a glance
- 1. Bound each term
For every i between 1 and n, log i is no larger than log n.
- 2. Add the bounds
There are n terms, so their sum is at most n log n.
- 3. Check the growth rate
An integral lower bound shows the sum is also Ω(n log n), making the tight bound Θ(n log n).
Let
To show that is , bound each term by the largest one. Since the logarithm is increasing, whenever . There are terms, so the sum is at most . This proves the requested upper bound directly.
The same sum has a useful exact interpretation: , by the logarithm rule that turns a product into a sum. An integral comparison shows that its growth is not merely bounded above by ; it is of that order.
Direct proof of the upper bound
Assume the logarithm has a fixed base greater than 1, so it is increasing. For every integer from 1 through ,
Summing these inequalities gives
Big O notation allows a constant factor in the upper bound. Here the inequality even holds with constant 1 for every positive integer (including , where both sides are zero). Therefore .
The logarithm base does not affect the asymptotic result. Changing from base to base , where both are greater than 1, multiplies every logarithm by the fixed constant . Big O and Big Theta growth rates are unchanged by such a constant factor.
Why the bound is tight
To establish a matching lower bound, use the fact that is increasing. With the natural logarithm, on each interval for , the function is no larger than . Thus
For sufficiently large , the right-hand side is at least a positive constant times . For example, when , . The upper bound is , so together these show
The same conclusion holds for any fixed logarithm base greater than 1. The integral is just a convenient way to establish the lower bound; it is not needed for the original Big O proof.
Worked example
Take and use natural logarithms. The sum can be evaluated using the factorial identity:
The simple upper bound gives , so the sum is indeed below . The bound need not be an equality: Big O describes how the sum grows as increases, not its exact value for each .
Common mistakes
- Treating the sum as identical terms. The terms differ, but each is no greater than ; this is what makes the term-by-term bound valid.
- Confusing an upper bound with an exact formula. The expression is a convenient bound, not the value of the sum. The exact value is .
- Claiming without specifying the logarithm convention. In algorithm analysis, the base is usually fixed and greater than 1. Its choice changes only a constant factor.
- Forgetting the tightness question. The direct comparison proves Big O. The integral comparison supplies a lower bound, which justifies the stronger statement .
If this sum appears in an algorithm analysis, you can use as an upper bound. When you need a tight asymptotic description, use .
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.