Quiz Entry - updated: 2026.11.27
What is the lexicographic order of $d$-tuples?
Compare the tuples dimension by dimension from the left: the first components decide; only if they are equal does the second component decide, and so on. Formally, $(x_1, \ldots, x_d) < (y_1, \ldots, y_d)$ if $x_1 < y_1$, or $x_1 = y_1$ and $(x_2, \ldots, x_d) < (y_2, \ldots, y_d)$.
A $d$-tuple is a sequence of $d$ keys $(k_1, \ldots, k_d)$, and $k_i$ is called its $i$-th dimension. The definition is recursive: a tie in the first dimension hands the decision to the rest of the tuple. Familiar examples:
- Spreadsheet sorts by several columns: last name, then first name for equal last names, then age.
- Words in a dictionary: the first letter decides, then the second, and so on: "radix" comes before "range" because d < n in the third letter.
- Dates as (year, month, day): (2026, 3, 31) < (2026, 11, 1).
- Points in space as their coordinates $(x, y, z)$, ordered by $x$ first.
- Version numbers as tuples: $(1, 10, 2) > (1, 9, 5)$ because $10 > 9$, although the strings "1.10.2" and "1.9.5" compare the other way round, character by character.
Python compares tuples exactly like this: (2, 1, 4) < (2, 4, 6) is True. In Java, Comparator.comparing(…).thenComparing(…) builds the same order from one comparator per dimension.
Go deeper:
Lexicographic order: Cartesian products — the order on tuples of any length, defined exactly as here.