Discrete Mathematics and Combinatorics

Latin Squares, Sudoku and Experimental Design

See how a grid with each symbol once per row and column powers Sudoku puzzles, fair experiments and a famous problem of Euler.

Key takeaways

  • A Latin square places n symbols in an n × n grid so that no symbol repeats in any row or column.
  • A cyclic shift builds a Latin square of every size, but the number of different squares grows extremely quickly.
  • A completed Sudoku is a Latin square whose nine boxes also contain each digit once.
  • Experimenters use Latin squares to balance two sources of unwanted variation without testing every combination.
  • Two squares are orthogonal when overlaying them produces every ordered pair once, a property Euler studied and partly misjudged.

A Latin square is an n × n grid filled with n symbols so that each symbol appears exactly once in every row and exactly once in every column. A finished Sudoku is a 9 × 9 Latin square with one extra rule about its 3 × 3 boxes. The same arrangement helps scientists compare treatments fairly when conditions vary in two directions at once.

Here is a Latin square of order 4, where order means the number of rows:

A B C D
B C D A
C D A B
D A B C

Building one and counting them

The square above is the easiest recipe: write the symbols in order, then shift each new row one step to the left. Using the numbers 0 to n − 1, the entry in row i and column j is the remainder of i + j after dividing by n. This is addition in modular arithmetic, and it works for every n.

More generally, the multiplication table of any finite group is a Latin square. The converse fails: from order 5 onward there are Latin squares that cannot be turned into a group table by renaming and reordering.

Order Number of Latin squares
1 1
2 2
3 12
4 576
5 161,280

The count for order 9 is roughly 5.5 × 10²⁷. No simple formula practical for computing these numbers is known, and exact values have been found only for small orders.

A square is called reduced when its first row and first column are in standard order. There are 4 reduced squares of order 4. Permuting all 4 columns and then the last 3 rows generates 24 × 6 = 144 squares from each, giving 4 × 144 = 576.

Sudoku as a constrained Latin square

Sudoku adds nine boxes that must each hold the digits 1 to 9. This cuts the number of valid completed grids to 6,670,903,752,021,072,936,960, about 6.7 × 10²¹, a figure computed by Bertram Felgenhauer and Frazer Jarvis in 2005. Many of these are the same up to relabeling digits or swapping rows within a band.

A puzzle is a partly filled grid with exactly one completion. In 2012 Gary McGuire and colleagues reported an exhaustive computer search showing that no puzzle with 16 or fewer clues has a unique solution. Puzzles with 17 clues exist.

Solving techniques are small pieces of logic:

  • Single candidate. A cell for which eight digits are ruled out must hold the ninth.
  • Single place. If only one cell in a row, column or box can take a digit, it goes there.
  • Pairs. If two cells in a unit can only be the same two digits, remove those digits from the rest of the unit.

Deciding whether a partly filled grid can be completed is quick for a 9 × 9 puzzle by computer. For general n² × n² grids the problem is NP-complete, so no efficient method for all sizes is expected. The same is true of completing a partial Latin square. NP-complete problems through examples explains what that label means.

A fair field trial

Say you want to compare four fertilizers, A to D, on a square field. The soil gets wetter from north to south and richer from west to east. If fertilizer A always sat on the wet side, you could not tell its effect from the water's.

Divide the field into a 4 × 4 grid and assign fertilizers by a Latin square. Every fertilizer appears once in each row (each moisture level) and once in each column (each soil level). When you average the results for one fertilizer, it has sampled every row and every column equally, so those differences cancel in the comparison.

Testing all combinations of 4 rows, 4 columns and 4 fertilizers would need 64 plots. The Latin square uses 16.

What a Latin square design balances
16 plots 4 treatments in a 4 × 4 grid Caveat Assumes rows and columns do not change treatment effects Chance Pick the square and labels at random Row effect Each treatment visits every row once Column effect Each treatment visits every column once 16 plots 4 treatments in a 4 × 4 grid Row effect Each treatment visits every row once Column effect Each treatment visits every column once Chance Pick the square and labels at random Caveat Assumes rows and columns do not change treatment effects

R. A. Fisher and colleagues promoted such designs in agricultural research in the 1920s and 1930s. Rows and columns need not be physical. They might be test subjects and time slots, or machines and operators.

Two conditions matter. The square should be chosen with random shuffling, so that hidden patterns do not line up with it, in keeping with the logic of control groups and randomization. And the usual analysis assumes the effects simply add. If a fertilizer works especially well on wet soil, that interaction can distort the result.

Why the averages cancel

Suppose each yield is a baseline plus a row effect, a column effect, a fertilizer effect and some random noise. Average the four plots that received fertilizer A:

mean for A = baseline + (average of all 4 row effects)
                      + (average of all 4 column effects)
                      + effect of A + average noise

The same is true for B, with the same row and column averages. Subtract one mean from the other and the baseline, rows and columns disappear, leaving the difference between A and B plus noise. That cancellation is the whole point of the design.

With a poorly chosen layout, say A in the entire top row, the A average would contain one row effect four times over, and nothing would cancel it.

Balancing the order of testing

When each person tries several products in sequence, the one tried just before may color the next judgment. Some Latin squares handle this too:

Person 1:  A B D C
Person 2:  B C A D
Person 3:  C D B A
Person 4:  D A C B

Each product appears once in each position. In addition, each of the 12 ordered pairs, such as A immediately before B or B immediately before A, occurs exactly once across the rows. Squares with this property are often associated with the statistician E. J. Williams.

Orthogonal squares

Take two Latin squares of the same order and lay one on top of the other. If every ordered pair of symbols appears exactly once, the squares are orthogonal.

A B C        1 2 3        A1 B2 C3
B C A   +    3 1 2   =    B3 C1 A2
C A B        2 3 1        C2 A3 B1

All nine pairs appear. In an experiment, a second orthogonal square lets you balance a third nuisance factor in the same 9 trials. For instance, rows could be days, columns could be ovens, letters could be recipes and numbers could be bakers. Each baker then uses each recipe once, and also meets every day and every oven once.

The pair above comes from simple formulas on remainders after division by 3. With rows and columns numbered 0 to 2, the first square holds i + j and the second holds j − i, shifted into the symbols shown. The same trick, using two different multipliers, produces orthogonal pairs for every prime order from 3 upward.

Euler's officers

Leonhard Euler posed a puzzle: arrange 36 officers, one of each of 6 ranks from each of 6 regiments, in a square so that each row and column contains every rank and every regiment once. This asks for two orthogonal squares of order 6.

Euler suspected it was impossible, and Gaston Tarry confirmed that around 1900 by systematic case checking. Euler also conjectured that no orthogonal pair exists for orders 10, 14, 18 and so on. That was wrong. Around 1959 and 1960, R. C. Bose, S. S. Shrikhande and E. T. Parker showed that pairs exist for every order except 2 and 6.

How many squares can be mutually orthogonal? At most n − 1 for order n at least 2. The limit is reached whenever n is a power of a prime, using arithmetic in finite fields. A complete set of that size is equivalent to a finite geometry called a projective plane, which connects to combinatorial designs and the Fano plane.

Other uses

Latin squares appear in scheduling round-robin events, in arranging the order in which tasters sample products, and in some error-correcting schemes. In the language of graphs, filling a Latin square is the same as coloring the lines of a complete bipartite graph with n colors so that no two lines at a point match. Hall's marriage theorem implies that a rectangle with fewer than n complete rows, each row valid and no column repeating, can always be extended by another row.

Common questions

Does a Sudoku puzzle require arithmetic?

No. The digits are only labels. You could use nine colors or letters.

Why the name "Latin"?

Euler used Latin letters as symbols in his studies, and the name stuck. When a second square used Greek letters, the overlay became known as a Graeco-Latin square.

Can I use a cyclic square in a real experiment?

It balances rows and columns, but its regular diagonal pattern could coincide with a trend across the field. Randomly permuting rows, columns and treatment labels before use guards against that.

Written for 4Mathematics with AI writing tools and not reviewed line by line by a person. Check anything you rely on against a textbook or primary source. Report an error.

Keep reading

All 45 articles in Discrete Mathematics and Combinatorics →

Latest news on this topic