Ask a room of developers whether a piece of code is fast and the answers usually name a machine, a language, or a number of milliseconds. Each answer can be true and still mislead. A timing measures one run, on one machine, with one size of input. It says nothing reliable about the run that matters most: the one after the product succeeds, the data grows, and a customer is having the busiest day of the year.
The more useful question is plainer and harder. As the input grows, how does the work grow? Answering it by counting, rather than by timing, is the discipline that decides whether software survives its own success.
Count operations, as a function of size
Complexity analysis starts with a single letter. Let n stand for the size of the input: the number of records, items, characters, or nodes a method has to handle. The analysis then writes the work as a formula in n: one method performs about n comparisons, another about n² ÷ 2, a third about as many steps as the number of times n can be halved before reaching 1.
That last count has a name, the logarithm, written log₂ n, and it grows with remarkable slowness. Log₂ 1,000 is just under 10, because 2¹⁰ = 1,024. Log₂ 1,000,000 is just under 20.
The growth class, written in big-O notation — O(n), O(n²), O(log n), O(n log n), O(1) — states the shape of the count with constant factors and smaller terms stripped away. The stripping is deliberate. Big-O is a claim about the shape of growth, not a stopwatch reading. Methods doing 3n + 5 and n operations are both O(n). A method doing n² ÷ 2 operations is O(n²), and no constant factor rescues it: at n = 1,000 it performs about 500,000 operations where a linear method performs about 1,000.
The same search, two different shapes
The simplest contrast makes the point without any cleverness. A linear search scans a list from the front until the target appears. In the worst case it makes one comparison per element: n comparisons, O(n). On 1,000 items, at most 1,000 comparisons. Double the input and you double the worst case.
A binary search works on a sorted array. It probes the middle, discards half of what remains, and repeats: one comparison per halving, at most 10 on 1,000 items and at most 20 on 1,000,000. That is O(log n). The gap between the two methods is not coding skill or a faster machine. It is the shape of the count itself.
The other common shapes sit on the same ladder. O(1), constant, means the count does not grow with n at all: the work for ten items equals the work for ten million, as when an array hands over the element at a computed address. O(n²) is the shape of pairs, every item meeting every item: harmless at n = 100 (10,000 operations) and ruinous at n = 100,000 (10,000,000,000). Beyond those sit the exponential shapes, 2ⁿ, where each added item doubles the work, and at n = 60 the count exceeds a billion billions. No machine outruns that shape. A developer who can place a method on this ladder from its loop structure alone, without running it, holds the core skill here.
Count the right thing, and name the case
Counting has a second half that beginners skip: count the right thing, and say which case you counted.
The worst case bounds what can happen. The average case describes what usually happens. The best case is mostly useful for catching self-deception. A method whose average case is fine and whose worst case is catastrophic is not a practical method with a footnote. It is a bet, and should be named as one.
There is also a second resource to count: space. A method can trade memory for time — a precomputed table, a copy, an index — and an honest analysis counts both currencies and states the trade.
And some costs are forced by the problem itself, not by your method. Any method that must look at every record at least once cannot beat O(n), because the reading alone costs n; any comparison-based sort cannot beat O(n log n) in the worst case. Knowing what is forced stops two errors: hunting for a method that cannot exist, and apologizing for a cost no one could remove.
The shape was waiting for the input
At Solmere Systems, whose dispatch dashboard, Routeboard, runs through the course, the team learned this the expensive way. A customer lookup scanned the full customer list, and it felt instant while customers numbered in the hundreds. Then one large client imported 60,000 customer records. The same lookup's worst case grew from hundreds of comparisons to 60,000 per call, and the dashboard made that call on every screen refresh.
This answers the common objection that big-O is academic theory and what matters is how fast code runs on your machine. Big-O is not a substitute for timing. It is the instrument that tells you whether today's timing will survive tomorrow's input. Developers who skip it are not being practical; they are arranging to be surprised later, at production scale, when surprise is most expensive.
You do not choose whether your code has a growth shape. Every method has one. You choose only whether you know it before your largest customer teaches it to you.
Applying this distinction to an unfamiliar loop, under a stated case, with both time and space counted, is where it becomes a skill rather than a slogan — a skill built by working problems and having a wrong shape caught before it hardens into a habit.
Experience it, don’t just read about it
Counting operations, not guessing from timings is Concept 1 of Algorithms and Data Structures (Course No. 204), from Cognosco Learning, a learning company powered by AI. The course builds the full discipline beyond this distinction — Arrays and Dynamic Arrays, Hash Tables, and Dynamic Programming — each worked through with an Agentic Socratic AI coach, one learner at a time. Try a Free Preview at cognoscolearning.com.
Navigate your own course.
© 2026 Cognosco Learning. All rights reserved.