Once you have stopped losing socks, you are left with a pile of them to match. Is there a most efficient way to sort them? According to cognitive scientist Professor Brian Christian and science writer Tom Griffith in their book Algorithms to Live By, the answer is yes — and the method comes straight from computer science.
To sort socks efficiently, the book Algorithms to Live By recommends radix sort: split the pile into subgroups such as color, then subdivide by a second trait like length, and match socks inside the smaller piles. For a small pile, the pigeonhole principle works: pick half the socks plus one and you are certain of at least one pair. Ten socks need six picked. Simplest of all, buy only one type so there is nothing to sort.
How does radix sort work for socks?
Instead of picking one sock from the pile and hunting for its twin across the whole heap, you separate all the socks into subgroups — for example, by color. You can then subdivide those socks again according to a different criterion, such as length. Matching socks inside each smaller pile is far easier than searching the original pile, because the number of candidates is reduced at every step.
| Sorting step | Action | Why it helps |
|---|---|---|
| First pass | Split the pile into subgroups by color | Shrinks the search to one color at a time |
| Second pass | Subdivide each group by a second trait, e.g. length | Reduces candidates again within each color |
| Final step | Match socks within the smallest piles | Pairs are now quick to spot |
What is the pigeonhole principle?
For a small number of socks, the authors suggest the pigeonhole principle instead. It says that if you pick half of all the socks plus one, you are certain to find at least one pair. The logic is simple: with only two socks in a pair, once you have picked more than half the pile, two of them must match.
Worked example: ten socks
Take a load with ten socks:
Picking six socks at random from the ten guarantees at least one matching pair in that smaller pile. The same rule scales: from twenty socks, picking guarantees a pair.
Is there an even simpler solution?
Yes. If all your socks are identical, there is no need to sort them at all. The book's tongue-in-cheek conclusion — "buy only one type of sock" — removes the matching problem entirely rather than solving it faster.
FAQ
Should I use radix sort or the pigeonhole principle?
It depends on the pile size. The authors recommend radix sort for a large pile of socks, where splitting into subgroups saves the most searching, and the pigeonhole principle for a small load, where picking half plus one quickly surfaces a pair.
Does sorting socks change how many I lose?
No — sorting is what you do after the socks are already gathered. Preventing loss depends on the habits covered in the Sock Loss Index, such as cutting wash frequency and taking precautions; sorting simply makes the surviving socks easier to pair.
References
- Brian Christian and Tom Griffith, Algorithms to Live By — radix sort and the pigeonhole principle for matching socks.
- Omni Lost Socks Calculator, "Sort your socks like a pro(fessor)" section.