You have been doing this all unit without the words for it. In The Race you noticed that one lookup got slower with the file and the other did not. In Sorting by Hand you noticed that doubling the pile of cards more than doubled the work. Big-O is not a new idea; it is the vocabulary for the thing you already saw.

It answers one question, and refuses to answer any other: as the input grows, how does the work grow?

Count, do not time

Timings depend on your laptop, the weather in the room, and what the browser is doing. Counts do not. Count the operation that happens most often — comparisons, usually — and the pattern appears immediately:

def count_pairs(values):
    """Count how many times the inner line runs."""
    steps = 0
    for first in range(len(values)):
        for second in range(first + 1, len(values)):
            steps = steps + 1
    return steps
ItemsSteps
1045
20190
40780
803 160

Doubling the items roughly quadruples the steps. That is the signature you are learning to recognise, and it costs nothing to measure — no stopwatch, no assumptions, identical on every machine. Exactly, the count is , which is .

The notation, and what it deliberately throws away

Big-O keeps only the term that dominates as grows, and drops constants. becomes ==== — because at the term is a thousand times bigger than the term, and the does not change the shape at all.

Big-OCalledDoubling does whatWhere you have seen it
constantnothingdictionary lookup (average)
logarithmicadds one stepSearching, binary search
lineardoubles the worklinear search, one loop
linearithmicslightly more than doublesmerge sort, sorted()
quadraticquadruples the workbubble, insertion, selection
exponentialsquares the worknaive Fibonacci

Read the table as a ladder. One step down it is not a small inconvenience: at a million items, is about 20 operations and is a trillion. No faster laptop closes that gap, which is why “just buy a better computer” is not an engineering answer.

What Big-O hides, and why you still measure

Big-O is a statement about growth, not about speed today. Four honest caveats, all of which you have already met:

  • Constants are real. Two algorithms can differ by a factor of fifty. Big-O says they will stay a factor of fifty apart.
  • Small inputs do not care. For thirty volunteers, every algorithm on this page is instant. Choosing the clever one anyway, and making the code harder to read, is a bad trade — and Reading Somebody Else’s Code is the bill that arrives later.
  • Best, average, worst are different questions. Insertion sort is on already-sorted data and on reversed data. Quoting one number without saying which case is how people mislead themselves.
  • Memory counts too. Merge sort is faster than insertion sort and uses extra space to do it. “Efficient” always means efficient in something.

What a defensible claim sounds like

Not “binary search is faster”. Instead: “Linear search is , binary search is but requires sorted data. Our card file is sorted and read far more often than it is written, so we sort once and binary search after. Counted comparisons on 100 000 cards: 100 000 against 16. Measured on one laptop, the search went from about 1 ms to under 1 µs — your machine will differ, the ratio will not.” That paragraph is what the search analysis expectation is asking for, and it is worth marks in The Structure Study and The Software Project.

Theoretical limits and complexity classes

Big-O is part of a larger mathematical field: theoretical computer science and computational complexity theory. Computer scientists classify problems by their intrinsic difficulty, independent of hardware:

  • Lower bounds on problems: While an algorithm like insertion sort is and merge sort is , theoretical proofs establish that any comparison-based sorting algorithm requires at least comparisons in the worst case. Using a decision tree model, sorting items corresponds to identifying one of possible permutations. A binary decision tree with leaves must have a minimum height of .
  • Complexity classes ( vs ): Problems solvable in polynomial time (like searching, sorting, and shortest-path graph algorithms) belong to class . Problems whose solutions can be verified in polynomial time belong to . Whether remains the central open question of theoretical computer science.
  • Computability and undecidability: Alan Turing proved that certain problems (like the Halting Problem — determining whether an arbitrary program will eventually stop running) cannot be decided by any algorithm.

Understanding theoretical bounds helps engineers recognize when a problem is provably hard and when an optimal algorithm has already been found.

Timing still matters — it is how you find out which part of a real program is slow, which is almost never the part you guessed. Profiling and Timing Code has the method; the rule is to measure before you optimise, and to keep the correct version until the fast one passes the same tests.

Do the counting yourself in Efficiency Practice, watch the shapes appear in Searching and Timing It and Sorting and Timing It, and see the exponential case bite in Recursion.

Curriculum connection

C2.2

compare the efficiency of linear and binary searches, using run times and computational complexity analysis (e.g., to analyse the number of statements executed, the number of iterations of a loop, or the number of comparisons performed);

Link to original

C2.3

compare the efficiency of sorting algorithms, using run times and computational complexity analysis (e.g., to analyse the number of statements executed, the number of iterations of a loop, or the number of comparisons performed);

Link to original

C2.4

identify common pitfalls in recursive functions (e.g., infinite recursion, exponential growth in recursive algorithms such as Fibonacci numbers).

Link to original

D4.2

investigate a topic in theoretical computer science (e.g., cryptography, graph theory, logic, computability theory, attribute grammar, automata theory, data mining, artificial intelligence, robotics, computer vision, image processing), and produce a report, using an appropriate format (e.g., website, presentation software, video);

Link to original