Counting
Counting instead of timing
Why every measurement on this site is an exact operation count rather than a duration, what the instrumented array counts and what it deliberately does not, and the check that refuses to measure an algorithm that did not work.
Fitting a class to measurements
How a complexity class is fitted to measured operation counts, why the ratio test beats a slope on log–log axes, what tolerance separates a real fit from a wrong one, and the two claims on this site that the fit refused to grant.
One run, four counts, four answers
Why comparisons, swaps, reads and writes rank the same algorithms in different orders, what each count is actually good for, and how the choice of cost model quietly decides the answer to every comparison anyone makes.
The count somebody chose
Six countable quantities, six rankings, and how far apart they are — with the pairwise disagreements measured, and what a cost model is once it is written down as the weighting it always was.
Counting the coin flips
Randomness as a measured resource beside comparisons, cache misses and slots — how it is charged, what each randomised algorithm here consumes, and the one class the site's vocabulary could not grant.
Two pivots and what they cost
Dual-pivot quicksort measured on four counters, none of which agrees with the others, and what it means that an algorithm was adopted on the strength of a weighting.
The exchange rate nobody wrote down
The record size as an explicit exchange rate between the counts this site takes, where each pair of sorts changes places, and the one case where the model can be checked and is wrong.
The count that came from somewhere else
An audit of this collection's own reproducibility claim, the two measurements that pass through an unspecified routine, and what counting its comparisons reveals about it.
A distribution computed rather than sampled
Quicksort's comparison count as an exact probability distribution, computed by convolving its recurrence, laid over histograms of real runs. The exact moments say how many runs a sampled mean needs for a stated precision — 793 for one per cent at sixteen elements, 85 at four thousand — because the spread grows more slowly than the mean.
A count over every input
Five sorts run on every permutation of eight elements, with the inputs a benchmark generator names marked among them. Three of the five have worst cases no named input reaches, one has every named input at its best case, and first-element quicksort's average over every input equals randomised quicksort's expected count exactly.
The worst case found by climbing
A local search for worst-case inputs, validated against exhaustive enumeration at eight elements and then run where enumeration cannot reach. It reaches merge sort's exact worst case at every size, stalls on a plateau at about half of first-element quicksort's, loses to McIlroy's adversary on the quicksorts and to nothing on heapsort, where no worst case is known.
A worst case ten positions wide
Each sort's worst-case input with a fraction of its positions reshuffled. First-element quicksort's sorted input loses half its cost to about ten reshuffled positions at every size measured, while insertion sort's reversed input keeps 71% at half reshuffled, exactly as a count of inverted pairs predicts. At eight elements, the number of orderings that reach each sort's worst case runs from 128 to 10,240.
The sort whose count has no distribution
Batcher's odd–even merge sort network measured against the adaptive sorts. Its comparison count is fixed by n alone, sitting between merge sort's worst and heapsort's best at eight elements and growing to four times merge sort's worst at 65,536; its exchanges still vary; and the zero–one principle lets every input of sixteen be checked in 65,536 runs, with each of its 63 comparators shown to be necessary.
The count of the part that was read
Six ways to return the k smallest of n keys in order, counted against k from one to all of them, with two floors — one from elements that must lose, one from information — and the demonstration that their sum is not a floor. A knockout tournament stays near the floor wherever the floor is tight and, read to the end, makes exactly merge sort's comparisons.
The order equal keys keep
Stability measured rather than quoted: which sorts keep equal keys in order, how many pairs the others move, what the tie share is as the distinct keys vary, and what decorating each record with its position costs each sort in comparisons and in space.
The sort that makes none of them
Radix sort counted in the same four primitives as every comparison sort here: no comparisons at any digit width, reads and writes set by the key's width rather than by the number of orderings, and a cache miss rate that is the reason it is not the answer.
Two floors that can be added
A third floor under returning the k smallest in order — the elements that must lose, plus the comparisons the outputs' own order needs — proved disjoint, computed at every k, and checked against the exact optimum found by minimax at sizes where it can be computed.
The questions a sort asks twice
Every comparison a sort makes, checked against the transitive closure of the comparisons before it, and every comparison priced in the orderings it actually eliminated — counted exactly as linear extensions of the partial order the sort has built.
The price of remembering an answer
Six sorts given two records of what they have learned — the pairs already compared, and the transitive closure of every answer — with the record's lookups and upkeep counted in word operations beside the comparisons it saves. The break-even price of a comparison at sizes from 32 to 512, the cost as that price rises, and the inputs on which either record has anything to remove.
The comparisons that name the answer
A third term for the floor under returning the k smallest in order: the bits needed to name the first k − 1 outputs, on top of the n − k eliminations. Checked against the exact optimum found by solving over every partial order of up to six elements, split into its parts at two sizes, and set against a tournament, a heap and a selection that sorts afterwards at k from 1 to 65,536.