Topic Guide 01 — Sorting & Classification

Order from Mixed Pieces

Close-up photograph of hands sorting carved timber counters with geometric notches on a dark charcoal table

At first glance, putting a handful of mixed objects into order feels elementary. Yet as soon as the sorting criterion shifts from obvious visual size to a compound logical constraint—or when the permitted moves are restricted to specific pairwise swaps—sorting transforms into one of the richest territories in recreational mathematics. From Édouard Lucas's 1883 Tower of Hanoi to Donald Knuth's analysis of minimum-comparison sorting networks in Volume 3 of The Art of Computer Programming, sorting puzzles ask a precise question: how can we establish global order using the fewest local observations?

1. Taxonomy vs. Permutation Sorting

Adult sorting challenges generally divide into two structural families: attribute partitioning (classification) and constrained permutation. Recognizing which structure you are facing determines your opening move.

2. Minimum-Comparison Balance Challenges

Suppose you have five visually identical brass weights that differ slightly in mass, and a two-pan balance scale that only reveals which of two chosen weights is heavier. How many weighings are strictly required in the worst case to put all five weights into exact ascending order?

Many solvers begin by inserting weights one at a time (binary insertion), which can require up to 8 comparisons. By contrast, the Ford–Johnson merge-insertion strategy solves the five-weight problem in at most 7 comparisons every time:

  1. Compare Weight A against Weight B (1st comparison), and Weight C against Weight D (2nd comparison). Assume without loss of generality that A < B and C < D.
  2. Compare the two heavier winners, B and D (3rd comparison). Suppose B < D. You now have a three-element chain: A < B < D, with C known to be lighter than D.
  3. Insert the unweighed fifth piece, Weight E, into the chain (A, B, D) by testing E against the middle element B first (4th comparison), and then against either A or D (5th comparison).
  4. Finally, insert C into the three or four items below D using at most 2 comparisons (6th and 7th comparisons).
Sorting Method Worst-Case Comparisons (5 Items) Primary Cognitive Bottleneck Best Puzzle Application
Adjacent Bubble Swaps 10 comparisons High repetition; easy to lose count of passes Physical pegboards where only neighboring slots can exchange
Binary Insertion 8 comparisons Maintaining a sorted sub-row while testing a newcomer Card-hand ordering and sequential reveal challenges
Ford–Johnson Tournament 7 comparisons (theoretical optimum) Tracking partial order trees before final insertion Balance-scale puzzles and hidden-value deduction

3. Worked Classification Exercise: The Three-Trait Counter Tray

Consider six wooden tokens labeled P, Q, R, S, T, U. Each token has three observable traits: Material (Oak or Walnut), Edge (Smooth or Grooved), and Dot Count (2, 3, or 5 dots). You must sort them into two trays of three tokens each such that within each tray, Material is identical, Edge is either all identical or cannot be uniform, and the sum of Dot Counts in Tray Alpha equals the sum of Dot Counts in Tray Beta.

Step-by-Step Partitioning Solution

Because the primary constraint requires identical Material within each tray, we immediately test the partition by wood species: Oak tokens are {P, R, T} and Walnut tokens are {Q, S, U}. Next, check the dot-sum invariant: Oak sum = 5 + 2 + 3 = 10; Walnut sum = 3 + 5 + 2 = 10. Both constraints hold simultaneously without needing a single trial swap.

4. Parity Invariants in Sliding and Swapping

Whenever a sorting puzzle restricts how pieces move—such as swapping two pairs at once, or cycling three pieces—always check the permutation parity. Every permutation of items has a mathematical count of "inversions" (pairs of items where the larger value sits to the left of the smaller value). A single swap of two items always flips the inversion count from odd to even or even to odd. Therefore, if a puzzle's legal move consists of rotating three pieces (A → B → C → A), which equals two swaps, the parity of inversions can never change. Recognizing this invariant saves hours of futile effort on impossible configurations.