O, Omega and Theta, defined properly
Three statements about how one function compares with another once n is large enough, each with two constants you have to be able to produce.
Exact operation counts are unwieldy and, worse, dishonest about their own precision: the 5 in came from a decision about whether an addition and an assignment are one action or two. What is worth keeping is the shape. The tool for keeping only the shape is asymptotic notation, and it is built on a comparison you can watch happening.
Take an exact count, , and a candidate shape, . Multiply the shape by 4 and print both columns.
Change the 4 to a 3 and run it again. Now find the smallest whole number multiplier that ever works.
For small the 100 dominates and is far ahead. At , and , so the comparison flips, and it never flips back: the gap between and grows like while grows like .
Two numbers came out of that: the multiplier 4, and the point 13 after which the claim holds. Those two numbers are the whole content of the definition.
Big O
Read the following as: grows no faster than , apart from a constant factor, once is large enough.
To claim you must be able to produce a and an that work. The run above produced them: and . That is a complete proof that , provided you also check the inequality never fails again after 13, which the algebra does.
Here is that check written out. The claim rearranges to . The left side is increasing for , since raising by 1 adds , which is positive there. At it equals , which is at least 0. Being non-negative at 13 and increasing after it, it stays non-negative for every .
- 672
- 676
- , which must be at least 0
- 4
Set to 3 and drag as far right as it goes: the difference never turns positive. Set to 4 and find the smallest where it does.
Omega and Theta
Big O is an upper bound and says nothing about how small might be. The mirror image gives a lower bound.
For the same , take and . Then and , which is positive for every . So .
Combining the two results above with , and gives . Theta is the strongest of the three and the one to aim for, because it pins the growth rather than bounding it on one side.
It is equally important to be able to show a claim is false. Suppose someone asserts . By the definition there would be fixed and with for every . Divide both sides by , which is positive, to get for every . Now take to be whichever of and is larger. That is at least , so the inequality must apply to it, yet . The two cannot both hold, so no such pair exists and the claim is false.
Little-o and little-omega
Big O allows and to grow at the same rate; is true. The lower-case versions demand a strict gap by changing one quantifier from there exists a c to for every c.
Here is the full argument that . Fix any , however small. The requirement divides through by to give , that is . So take to be any whole number larger than ; for that is . Since a suitable exists for every , the claim holds.
That is exactly what fails for against : with the requirement is false for every , so is not .
Little-omega, written with the lower-case Greek letter , is the mirror image of little-o. It says grows strictly faster than : whatever multiple of you name, however large, is past it from some point on and stays past it.
Here is the full argument that , in the same shape as the little-o one. Fix any , however large. The requirement is . Divide both sides by , which is positive for the values in question, to get . So any that is itself larger than will do.
To name one, write for the ceiling of , meaning rounded up to the nearest whole number, so and . Then is a whole number strictly greater than , and every is greater than as well. With that gives , and indeed while , which is larger. A suitable exists for every , so the claim holds.
And is not , for the same reason it is not : with the requirement is false for every . Little-omega, like little-o, refuses two functions that grow at the same rate.
| Notation | In words | Like |
|---|---|---|
| f = O(g) | f grows no faster than g | less than or equal to |
| f = Omega(g) | f grows at least as fast as g | greater than or equal to |
| f = Theta(g) | f and g grow at the same rate | equal to |
| f = o(g) | f grows strictly slower than g | strictly less than |
| f = omega(g) | f grows strictly faster than g | strictly greater than |
When both functions are positive and the ratio settles down, a limit gives the answer faster than hunting for constants. If tends to a finite number that is not 0, then . If it tends to 0, then , and in particular . If it grows without bound, then , and in particular . The ratio tends to 3, which confirms the Theta result in one line.
Is 4n + 7 = O(n squared)? And is it a useful thing to say?
It is true. Take c = 1 and n0 = 6: for n at least 6, n squared is at least 6n, which is at least 4n + 7 once n is at least 6 (since 6n - 4n = 2n is at least 12, and 12 is greater than 7). It is also a weak statement, because 4n + 7 = O(n) is true as well and rules out much more. O is an upper bound, so any looser bound above a true one is also true. When someone quotes a bound, the interesting question is whether it is tight, which is what Theta asserts.