Big-Oh Notation
The Big-Oh (read it as “big O”) notation lets us describe and compare the work an algorithm does without precisely counting the operations it performs.
Big-Oh has a formal, mathematical definition, but in this course we will work with an informal, intuitive understanding of it.
We use Big-Oh informally in this course
Strictly speaking, Big-Oh is an upper bound: saying something is means it grows no faster than a constant multiple of . In this course, when we say an algorithm “is ,” we will usually mean its tight dominant growth is linear.
Let’s revisit the work of linear search. We said that the work can be expressed as for some constants and . In the Big-Oh notation, we would say that the work of linear search is . The stands for “order of”. The is the canonical way to express a linear relationship between the work and the size of the input.
Let’s try this for another, hypothetical algorithm that does work. In the Big-Oh notation, we would say that the work of this algorithm is . The is the canonical way to express a quadratic relationship between the work and the size of the input.
How do we go from to ? It involves two steps.
- First, we suppress all coefficients. We set all constants to 1. This gives us .
- Second, we ignore (drop) all but the dominant term. This gives us .
I will justify both steps in the next two sections. For now, let’s take them as given and use them on an exercise.
Solution
This one is mostly algebra. I will not ask you a question like this on an exam. The point is to see the two steps carried out on a messy expression, not to be quick with the algebra.
I prefer to simplify the expression first, and then apply the two steps:
Now we apply the two steps. Suppressing the coefficients turns the expression into . Dropping all but the dominant term leaves . So the work is .
You might be wondering how I decided that is the dominant term. To compare two terms, divide one by the other and ask what happens as grows. Take and . Divide the first by the second and you get , which keeps growing as grows. So the first term grows faster than the second. Divide by and you get , which also keeps growing. The remaining terms , , , and grow more slowly than . So is the dominant term.
I assumed means here. That is the usual convention in computer science.