LOGBOOK

HELP

Quiz Entry - updated: 2026.11.27

What goes wrong in lexicographic sort if the passes run from dimension 1 to $d$, or if the sort used in each pass is not stable?

Run front to back, the last pass sorts by dimension $d$, so the result is ordered by the least important component, and the earlier passes only survive among ties. With an unstable sort, a pass may reorder tuples that tie in its dimension and destroy the order the earlier passes built.

The intuitive plan, sort by the most important key first and then by the next one, is exactly backwards. Both mistakes on the same five tuples:

  • Wrong direction. Sorting $(7,4,6)\;(5,1,5)\;(2,4,6)\;(2,1,4)\;(3,2,4)$ stably by dimension 1, then 2, then 3 ends with $(2,1,4)\;(3,2,4)\;(5,1,5)\;(2,4,6)\;(7,4,6)$. That is ordered by the last component (4, 4, 5, 6, 6), not lexicographically: $(5,1,5)$ ends up before $(2,4,6)$.
  • Unstable pass. In the correct order of passes, $(2,1,4)$ and $(2,4,6)$ tie on their first component in the last pass, and the earlier passes have already put $(2,1,4)$ in front. A stable sort leaves it there. An unstable one, quick-sort for instance, may output $(2,4,6)$ first, although $1 < 4$ says otherwise.

The two conditions belong together: the backwards order gives the most important dimension the last word, and stability is what makes the earlier passes count at all.

From Quiz: ADS / Sorting Lower Bound, Bucket-Sort and Radix-Sort | Updated: Nov 27, 2026