What O(f) actually is
After thiswhat you will be able to doTest whether a cost belongs to O(f) by producing a valid multiplier and threshold, and explain why O(f) is a set rather than one value.
Questionwhat this lesson answersWe write T(n) = O(n^2) with an equals sign, yet you cannot swap the two sides and the right side is not a single number. What kind of object is O(n^2), such that a cost can be said to equal it?
Not coveredwhat this lesson leaves outWe define what it means to belong to O(f) and we find the two witnesses by hand for one function. We do not prove the rules for combining O(...) expressions, and we leave the lower bound alone.
There is a strange convention in algorithm writing. We write with an equals sign, even though the line is not an ordinary equality. You would never turn it around and write . The left side is a rule that gives a step count for each input size. The right side is not one number at all, and it does not even stand for one particular cost. So the equals sign is standing in for something else, and the rest of this lesson is about what.
First notice what the left side is. A rule that takes an input and returns a number is called a function. The cost rule takes an input size and returns a number of steps. A collection can hold more than one such rule, just as a shelf can hold more than one book. In mathematics, a collection treated as one object is called a set. To say that one thing is among the things in a set is called membership.
That is the kind of object on the right. is a set of functions, not a number and not one function. It contains every cost rule whose growth can be kept under some fixed multiple of once the input is large enough. The honest statement is : belongs to that set. The equals sign is standard shorthand, but it hides the membership claim and encourages the wrong picture.
What it takes to belong
We need a test for that claim. Write for the comparison rule, the shape we are using as a ceiling, and write for the cost rule under examination. The test asks for two ordinary numbers. First, find a positive fixed multiplier that lifts the comparison rule high enough. Call that multiplier . Then find a starting input after which the lifted comparison rule never falls below the cost. Call that starting point , pronounced “n zero”. A starting point of this kind is a threshold.
Those numbers are not decoration. Producing them is the evidence for the claim, so they are called witnesses. One witness says how high the ceiling is. The other says where we are allowed to begin asking it to cover the cost. Before that point the cost may do anything. After that point, every input must obey the comparison. A cost is never below zero, which accounts for the first comparison in the definition:
The symbol reads “there exists”. It is a demand to hand over an actual and an actual , not a promise that they feel plausible. The phrase “for all” is just as strict: one lucky large input is not enough. The ceiling has to stay above the cost from the threshold onward.
Find the witnesses
Return to the running cost. Here the cost rule and comparison rule are
Try a ceiling multiplier of . We need to know when the full cost is at most four copies of the comparison shape. Moving everything to one side turns that question into this:
The right side first becomes at least zero, or nonnegative, at . The two neighbouring inputs make the cutoff visible:
So and are witnesses. From input onward, the ceiling covers the full cost. The result is not that the cost has become exactly four copies of . It is that belongs to the set .
The number four was not arbitrary, though it was not unique. Look at the piece with the highest power of : its coefficient is . That coefficient is called the leading coefficient because it belongs to the leading, highest-power piece. The ceiling multiplier must be strictly greater than . If we try the boundary value, the extra linear and fixed pieces have nowhere to go:
That can never hold for a positive input. This is the same that the ratio in the earlier lesson approached from above. A multiplier above the leading coefficient clears the extra pieces eventually, and a multiplier at or below it does not.
A ceiling that can never catch up
Set the ceiling multiplier to two. No starting input can rescue it because the ceiling stays below the cost in the long run.
Witness picker
Move the ceiling, then choose where it starts
The accent curve is the ceiling selected by the multiplier. The shaded region begins at the chosen starting input, where the membership claim is allowed to begin.
- Cost
- Moving ceiling
The visible horizontal range expands when a later threshold matters. The shaded region is the part of the input line the current claim is asking to cover.
- Current c
- 2.0
- Current n zero
- 1
- Bound after start
- No
- Smallest working n zero
- No threshold works
No, the first failed input is 1 in the range checked through 10,000.
The controls make the price of the notation visible. A larger multiplier can begin sooner. A multiplier too low has no threshold at all. A valid claim needs both witnesses, not merely a curve that looks convincing over a short range.
Now “eventually” has an exact meaning: for every input at least . A statement such as is therefore a ceiling with a receipt attached, the multiplier and threshold that certify it. This lesson has built only that ceiling. It has not said how slowly the cost can grow, which is the question behind the Upper, lower, and tight door.
Doorswhat to read next, and why
- What we agree to throw awayThat lesson discarded the constant and the smaller terms by hand and asked you to trust it was safe. The definition here is what licenses it, and it names the price: two numbers you must be able to produce.
- Upper, lower, and tightO(f) is only a ceiling. It says the cost grows no faster than f and says nothing about how slow it may be. The floor and the exact fit are the lesson on upper, lower and tight.
- Limits and dominanceFinding the witnesses by hand works for one function. Deciding membership in general is usually done with a limit, which this lesson does not use.
- Sets and membershipThis lesson leans on the idea of a collection you can belong to. The general machinery of sets is assumed here, not built.
Symbolswhat each one means, and whether we defined it, measured it, or just started there
- O(f)Status: defined
- read "big O of f", the collection of all functions that, once the input is large enough, grow no faster than some fixed multiple of f
- cStatus: defined
- the fixed multiple, the first witness. For our polynomial it has to be larger than the leading coefficient 3
- n_0Status: defined
- the threshold, the second witness. The bound only has to hold once the input is at least this large
- g(n)Status: defined
- the cost being classified, here the running example 3n^2 + 500n + 20000
What these classifications mean
- defined
- circular by construction, true because we chose it
- empirical
- a measured claim about the world that could have come out otherwise
- bottoms out
- a primitive of the model, with nothing under it here
- door
- used here, explained elsewhere