What does Big O notation actually measure?
Big O notation measures the growth rate of an algorithm's resource usage (usually time or memory) relative to the size of its input. Instead of telling you exactly how many seconds a program will take to run, it tells you how much longer it will take if you double, triple, or massively increase the amount of data it has to process.
Think of it like buying groceries. If you buy a single item, it takes a certain amount of time. If you buy ten times as many items, does your shopping time stay the same, increase by ten times, or take a hundred times longer because you have to mathematically compare every item to every other item in your cart? Big O gives us a standardized mathematical way to describe this scaling behavior.
The Search for the Dominant Term
When we analyze an algorithm, we look for the operation that takes the most time as the input, which we call , gets infinitely large. This is called the dominant term. If an algorithm takes steps, the part will completely overshadow the and the when is a million. Big O isolates this dominant term, letting us say the algorithm is .
Why We Drop the Constants
In Big O notation, we ignore constants and coefficients. An algorithm that takes steps and one that takes steps are both considered , or linear time. This can feel weird at first. Why treat them the same? Because Big O only cares about the shape of the growth curve. Hardware speeds and language efficiencies change the constant multipliers, but an algorithm will eventually always beat an algorithm for large enough inputs, regardless of the constants.
Where Students Slip Up
The most common mistake is thinking Big O measures exact time in seconds or exact operations. A student might test their code on 10 items, see it finishes in 0.001 seconds, and think it is perfectly efficient. But Big O is about scaling. If that same code runs on 100,000 items, the time doesn't scale linearly; it scales quadratically, and those 0.001 seconds could suddenly become hours.
Worked through
Determine the Big O time complexity of a function that takes an array of size , prints every item once, and then compares every item to every other item to check for duplicates.
First, we break down the operations. Printing every item in the array takes steps. Comparing every item to every other item requires a nested loop: for each of the items, we look at the other items. This takes steps.
The total number of steps is .
Next, we apply the rules of Big O notation. We look at what happens as gets very large. The term grows much faster than the term, making it the dominant term. We drop the smaller term.
Therefore, the time complexity is .
Questions students ask
Ask about this topic
Where this comes from: Introduction to Algorithms (Cormen, Leiserson, Rivest, Stein) · Khan Academy: Algorithms Unit · Grokking Algorithms (Aditya Bhargava)
See also