The Formal Definition of Big-Oh
In this section I make the definition of Big-Oh a little more formal, and I introduce two related notations. This is for your information only. None of it will be on an exam.
What “asymptotic” means
The word comes from asymptote, a line that a curve gets closer and closer to as the curve extends without bound. “Asymptotic” describes behavior in the limit, as the input size grows without bound ().
This is what Big-Oh describes: how the work grows as the input gets large, not how much work there is for one particular input. It is also why the two rules are allowed. A constant factor and a lower-order term both change the cost at any fixed . Neither one changes how the cost grows as . So we drop them and keep the dominant term.
The formal definition of Big-Oh
Here is the formal definition of Big-Oh: if there are positive constants and such that
Here is the step count of the algorithm and is the function we write inside the . The definition says that past some input size , never goes above a constant multiple of .
Let’s check it on linear search. We counted its work as steps, and we said it is . So and . The definition asks us to find a and an such that for all . Try . Then we need . Subtract from both sides and that is . So the inequality holds for every , and works. We found the two constants, so by the definition.
Now look at what each constant did for us. The coefficient in front of was not a problem. We picked , which is bigger than , and that took care of it. Whatever the coefficient is, we can always pick larger. That is why we can suppress coefficients. The extra was not a problem either. It matters for small : at , is and is only . But we picked instead of , and that gives us one extra to spend. Once is or more, that extra is at least , which is enough to cover the . That is why we can drop lower-order terms. Past some input size, the dominant term with a slightly larger constant absorbs them. These are the two rules we have been applying by hand.
Upper, lower, and tight bounds
Big-Oh is an upper bound: it says the step count grows no faster than the function inside the . There are two related notations that bound the growth in other ways.
- , a lower bound (like ): grows at least as fast as . It is the same definition with the inequality flipped: for all .
- , a tight bound (like ): grows at the same rate as , meaning it is both and at once.
(There are also strict versions, little-o and little-omega, written and , for “grows strictly slower” and “grows strictly faster.”)
Because is only an upper bound, saying an algorithm is does not mean its work grows like . It only means the work grows no faster than that. Linear search is , but by the definition it is also and , since grows no faster than either of those. All three statements are true. Only the first one is useful. So in practice we always give the tightest bound we can. When we say linear search is , we really mean . Using where is meant is common, and this course does it too.