← Sorting · guided lesson

Sorting

1 / 18 · story

the story

Insertion sort (and the other O(n²) sorts)

Every tool here exists because something was too slow or broke without it. Here is what.

1956–1962 · E. H. Friend (1956 survey) · Kenneth E. Iverson (the name "bubble sort", 1962)

The simple sorts are older than their names. In 1956 E. H. Friend's survey in the Journal of the ACM compared methods such as inserting and exchanging — and found exchanging needs at least twice as many comparisons as inserting. Owen Astrachan's 2003 history of bubble sort found early books calling it "exchange sorting"; the first use of the name bubble sort in print he could find is Iverson's 1962 book A Programming Language. Knuth's verdict: bubble sort "seems to have nothing to recommend it, except a catchy name and the fact that it leads to some interesting theoretical problems".

the problem it solved

Sorting small amounts of data on early machines with almost no spare memory — and, today, finishing tiny or nearly sorted ranges faster than any O(n log n) sort can.

why it matters: without it

Library sorts would waste recursion and bookkeeping on 5-element ranges, and nearly sorted data would cost as much as random data.

sources: Friend — Sorting on Electronic Computer Systems (Journal of the ACM 3(3), 1956) ↗ · Astrachan — Bubble Sort: An Archaeological Algorithmic Analysis (SIGCSE 2003) ↗ · Knuth — The Art of Computer Programming, Vol. 3: Sorting and Searching, §5.2.1–5.2.2 ↗

also in this chapter: Merge sort · Quicksort · Quickselect · Counting sort · Radix sort · TimSort (Java's object sort) · Dual-pivot quicksort (Java's primitive sort) · The Ω(n log n) limit for comparison sorts