Basis LabBlog
← All posts
The subject itself20 Oct 20266 min read

Six growth shapes, and the one column worth memorising

Almost all work falls into a handful of shapes, and the useful question about each is what happens when the input doubles. That one sentence decides most design arguments before they start.

Basis Lab

There is a version of this subject that is a semester of proofs, and a version that fits on a postcard and settles most real arguments. This is the postcard.

The ladder

the shapen = 100n = 10,000n = 1,000,000doubling n multiplies the cost by
constant111nothing: it is the same
logarithmic71320nothing: it adds one step
linear10010,0001,000,0002
linear times logarithmic664132,87719,931,569a little over 2
quadratic10,000100,000,0001,000,000,000,0004
exponentiala 31-digit numbera 3,011-digit numbera 301,031-digit numberit squares it

Each rung is matched by work you already recognise: looking a key up in a hash table, halving a sorted list, scanning a list once, sorting it, comparing every pair, trying every subset.

The last column is the one to learn, because it compresses the whole table into six answers. Constant stays put. Logarithmic gains one step. Linear doubles. Linear times logarithmic a little more than doubles. Quadratic quadruples. Exponential squares.

That last one deserves its own line. Squaring is not a slowdown, it is a wall: a procedure taking a second at forty items takes about three hundred years at eighty. The honest word for exponential work is impossible rather than slow.

Where usable stops

The quadratic row is the boundary. A million rows compared pairwise is a million million operations, which is hours on a machine doing a billion a second.

Notice also how little separates the top three rows at any size, and how little that separation matters next to the gap below them. Arguments about whether something is linear or linear times logarithmic are usually not worth having. Arguments about whether it is linear or quadratic always are.

Reading the shape off timings, without reading the code

The doubling rule works backwards, which is how you establish the shape of code nobody wants to read, including library code and other people's services.

Measure at sizes that double, then look at the ratio between consecutive times rather than the times themselves.

sizeA, msB, msC, ms
1,0001.10.91.2
2,0002.23.62.6
4,0004.314.55.5
8,0008.758.111.9
ratio between rowsabout 2about 4about 2.2
the shapelinearquadraticlinear times logarithmic

Only the ratios are read, never the times, which is what makes the method independent of the machine it ran on. A ratio near one is constant or logarithmic, near two is linear, near four is quadratic, near eight is cubic, and a ratio that itself grows is something worse. The hard case is telling 2 from 2.2, and it is settled by going further out: at a hundred times the size, C drifts upward and A stays at two.

The curves cross, and below the crossing the worse shape wins

A better growth shape does not win at every size. Insertion sort compares every pair in the worst case and still beats merge sort below a few dozen items, because its per-item work is tiny and merge sort allocates and copies. Serious sorting libraries exploit exactly this: they sort small pieces with the quadratic method and switch above a threshold found by measurement.

And it is why quadratic code reaches production: on a developer's sample of fifty rows, the quadratic curve looks completely fine.

From the library

How Long It Takes

Eight lessons: counting steps rather than seconds, the shape of the curve, why the constants get dropped, best case against the one you actually get, space as a cost, occasionally expensive and usually free, and when the analysis lies.

It opens the track that ends with telling in advance which approach survives a million rows. The first lesson is free to read.