Little o, Little omega and Limits
and behave like and : is true, just as is. Often you want the strict version, "grows strictly slower than", for example to say that is genuinely better than and not merely no worse. That is what little o and little omega express. They are also where limits come in, which turn most asymptotic comparisons into a calculus exercise. The lesson ends with something never does: two functions that cannot be compared at all.
The previous lesson, O, Omega and Theta, gave the three big-letter definitions.
Little o: strictly slower
Compare the quantifiers with big O. For some constant must work. For every constant must work, however small, with an that may depend on . In words: eventually becomes a negligible fraction of .
- . Given , the inequality is , so works. For that is .
- . With the inequality never holds.
Little omega: strictly faster
, but . As with the big letters there is a transpose rule: if and only if .
The limit test
When for large , the strict bounds are exactly statements about the ratio:
The first equivalence is the definition of a limit in disguise: "for every , eventually " is what means. A ratio with a finite positive limit gives : eventually , so and are witnesses.
The word "eventually" deserves respect. Compare with . Writing , so that , the ratio is :
for k in [10, 20, 30, 40, 60, 80]:
ratio = k**3 / 2 ** (k / 2)
print(f"n = 2^{k:<3} (lg n)^3 / sqrt(n) = {ratio:.3g}")n = 2^10 (lg n)^3 / sqrt(n) = 31.2
n = 2^20 (lg n)^3 / sqrt(n) = 7.81
n = 2^30 (lg n)^3 / sqrt(n) = 0.824
n = 2^40 (lg n)^3 / sqrt(n) = 0.061
n = 2^60 (lg n)^3 / sqrt(n) = 0.000201
n = 2^80 (lg n)^3 / sqrt(n) = 4.66e-07
At the polylogarithm is 31 times larger. The limit is still 0, so ; the polylogarithm only falls behind for good near , about 660 million. A table of small can point the wrong way.
Computing limits with L'Hopital's rule
To find a limit of a ratio of functions of an integer , treat as a real variable . If both and go to infinity and are differentiable, L'Hopital's rule says , whenever the second limit exists.
Logarithms lose to every power. For any :
So , even for . Raising both sides to a power gives , and since was arbitrary, every power of a logarithm is for every .
Powers lose to every exponential. For an integer and , apply the rule times; each time the power drops by one and the exponential stays:
So . The Polynomials, Exponentials and Logarithms lesson uses both facts constantly.
Limits are sufficient, not necessary
The limit test only applies when the limit exists. A function can be with a ratio that never settles. Take
Then for all , so with , , , yet alternates between 3 and 1 forever. Running times of this shape are common: an algorithm that does extra work when is even, or when is not a power of two. When the limit fails to exist, go back to the definitions and find witnesses.
The same example shows that minus is bigger than . Define for even and for odd . Then , but (the odd values stay at 1) and (the even values equal ).
Two functions that cannot be compared
For real numbers, exactly one of , , holds. This trichotomy fails for functions. The classic counterexample is against . Their ratio is . Because the integers are spread evenly around the circle modulo , comes arbitrarily close to and to infinitely often. Near the ratio is close to , near close to . So the ratio is neither bounded above (no ) nor bounded away from 0 (no ).
The program looks at each range of between two powers of ten and reports the largest and smallest value of in it.
import math
for e in range(1, 6):
lo, hi = 10**e, 10 ** (e + 1)
vals = [(n ** math.sin(n), n) for n in range(lo, hi)]
big, n_big = max(vals)
small, n_small = min(vals)
print(f"{lo:>6} <= n < {hi:<7} max {big:10.1f} at n = {n_big:<6} min {small:.2e} at n = {n_small}") 10 <= n < 100 max 89.1 at n = 96 min 1.01e-02 at n = 99
100 <= n < 1000 max 984.8 at n = 988 min 1.04e-03 at n = 966
1000 <= n < 10000 max 9963.8 at n = 9973 min 1.00e-04 at n = 9995
10000 <= n < 100000 max 99708.7 at n = 99722 min 1.00e-05 at n = 99744
100000 <= n < 1000000 max 999821.3 at n = 999826 min 1.00e-06 at n = 999471
The maximum keeps growing roughly like and the minimum keeps shrinking roughly like . In the language of the analogy, is neither "at most" nor "at least" . Such pairs rarely come up as running times, but they are why a statement like "every function is , or of every other" is false.
The analogy, summed up
| Notation | Read as | Like | Ratio when the limit exists |
|---|---|---|---|
| at most | finite | ||
| at least | positive or | ||
| same order | finite and positive | ||
| strictly slower | 0 | ||
| strictly faster |
All five are transitive, , and are reflexive while and never are (), and implies but .
Test yourself
What is the essential difference between and ?
- needs some constant to work; needs every constant to work
- allows to be negative
- is only defined for polynomials
- There is none; they are synonyms
At , and . What follows?
- Nothing about growth: the limit of is 0, so
- The two functions are not comparable
for even and for odd . Which is true?
- , although does not exist
- is not because the limit does not exist
Why are and not comparable?
- Because is negative
- Because their ratio gets arbitrarily large and arbitrarily close to 0 infinitely often
- Because is not defined for integers
- They are comparable: