Tutorials › Graph Theory (Undergraduate) › A Worked Latin Rectangle Completion

Hall's Marriage Theorem · Tutorial 287 of 799

A Worked Latin Rectangle Completion

Learn how to translate each row-completion step into a bipartite matching and verify the completed Latin square.

Intermediate 9 min read

What You'll Learn

  • Define a Latin rectangle and the available symbol-column graph for its next row.
  • Read a matching as a valid assignment of distinct symbols to columns.
  • Complete small Latin rectangles by finding a matching at each stage.
  • Use Hall’s theorem to justify that a next row can be found.
  • Check a completed array row by row and column by column.
  • Recognize why choosing available symbols independently can fail.

Completing a Latin Rectangle by Matchings

A Latin rectangle is an array in which each row uses every symbol exactly once and no column repeats a symbol. To add a row, each column must receive a symbol not already above it, and the new row must use each symbol exactly once. These requirements are coupled: choosing an available symbol for one column may prevent its use in another. A bipartite matching records a set of choices that satisfy both requirements at once.

Definition: A Latin rectangle on \(n\) symbols with \(k\) rows is a \(k\)-by-\(n\) array whose entries are the symbols \(1,\ldots,n\), such that every row contains each symbol exactly once and no symbol occurs more than once in any column. A Latin square of order \(n\) is a Latin rectangle with \(n\) rows.

For each step, make one vertex for each column and one for each symbol. Join column \(c\) to symbol \(s\) exactly when \(s\) does not yet appear in column \(c\). A matching is a set of edges no two of which share a vertex. Thus, if a matching uses every column, its edges specify a choice for every column with no symbol chosen twice.

Definition: The available-pair graph of a Latin rectangle is the bipartite graph with column vertices \(c_1,\ldots,c_n\), symbol vertices \(s_1,\ldots,s_n\), and edge \(c_i s_j\) precisely when symbol \(j\) is absent from column \(i\).

In a graph with \(n\) column vertices and \(n\) symbol vertices, a matching covering all columns also covers all symbols: it has \(n\) edges, and those edges have distinct symbol endpoints among \(n\) symbols. It therefore assigns one available, distinct symbol to each column, exactly what a new row requires.

Why a Matching Can Always Be Found

We use Hall’s theorem, established in the earlier material on Hall’s Marriage Theorem. In the form needed here, it says that a finite bipartite graph with left vertex set \(C\) has a matching covering \(C\) if and only if every subset \(X\subseteq C\) satisfies \(|N(X)|\ge |X|\), where \(N(X)\) is the set of vertices adjacent to at least one vertex of \(X\).

Theorem: Every Latin rectangle on \(n\) symbols with \(k\) rows, where \(1\le k<n\), can be extended by one row to a Latin rectangle with \(k+1\) rows.

Proof. Let \(C\) be the set of \(n\) columns and \(S\) the set of \(n\) symbols, and form the available-pair graph. Fix a column. Its \(k\) entries are distinct, so exactly \(n-k\) symbols are absent from it; the column vertex therefore has degree \(n-k\). Fix a symbol \(s\). Since each of the \(k\) existing rows uses \(s\) exactly once, \(s\) appears in exactly \(k\) columns and is absent from exactly \(n-k\) columns. Thus every symbol vertex also has degree \(n-k\).

Take any subset \(X\subseteq C\). The number of edges from \(X\) is \((n-k)|X|\), since each column in \(X\) has degree \(n-k\). All these edges end in \(N(X)\), and each vertex in \(N(X)\) has total degree \(n-k\), so there are at most \((n-k)|N(X)|\) such edges. Consequently, \((n-k)|X|\le (n-k)|N(X)|\). Since \(k<n\), \(n-k>0\), and division gives \(|X|\le |N(X)|\). This holds for every \(X\subseteq C\), including \(X=\varnothing\), for which both sides are zero. Hall’s theorem gives a matching covering all columns. Use its symbol endpoints as the new row. Every entry is absent from its column, so no column repetition is introduced; and the matching uses each symbol at most once, so the new row has distinct entries. It has \(n\) entries chosen from \(n\) symbols, hence uses every symbol exactly once. The enlarged array is a Latin rectangle. \(\square\)

Corollary: Starting with a Latin rectangle on \(n\) symbols with \(r\) rows, where \(1\le r\le n\), repeated matching steps produce a Latin square after \(n-r\) additions.

Proof. At any stage with \(k<n\) rows, the theorem applies to the current Latin rectangle and supplies a valid next row. Inductively, after \(j\) additions, for \(0\le j\le n-r\), the array has \(r+j\) rows and is a Latin rectangle: the case \(j=0\) is the assumed starting array, and each subsequent step preserves the defining properties by the theorem. At \(j=n-r\), it has \(n\) rows and \(n\) columns, so it is a Latin square. If \(r=n\), no additions are needed and the starting Latin rectangle is already a Latin square. \(\square\)

Worked Completions

Worked Example: Completing a Four-Symbol Rectangle in Two Steps

Start with this Latin rectangle on symbols \(\{1,2,3,4\}\):

$$ \begin{array}{cccc} 1&2&3&4\\ 2&3&4&1 \end{array} $$

For the next row, column \(c_1\) already contains \(1,2\), so its available symbols are \(\{3,4\}\). Column \(c_2\) contains \(2,3\), giving \(\{1,4\}\). Column \(c_3\) contains \(3,4\), giving \(\{1,2\}\). Column \(c_4\) contains \(4,1\), giving \(\{2,3\}\). The available-pair graph has column set \(\{c_1,c_2,c_3,c_4\}\), symbol set \(\{s_1,s_2,s_3,s_4\}\), and edge set \(\{c_1s_3,c_1s_4,c_2s_1,c_2s_4,c_3s_1,c_3s_2,c_4s_2,c_4s_3\}\). One matching covering both sides is \(\{c_1s_3,c_2s_4,c_3s_1,c_4s_2\}\). It gives the row \((3,4,1,2)\).

Now the columns contain, from left to right, \((1,2,3)\), \((2,3,4)\), \((3,4,1)\), and \((4,1,2)\). Their respective missing symbols are \(\{4\},\{1\},\{2\},\{3\}\). The next available-pair graph has exactly the edges \(\{c_1s_4,c_2s_1,c_3s_2,c_4s_3\}\), which form a matching covering every vertex. The final row is \((4,1,2,3)\).

Check: The four rows are \((1,2,3,4)\), \((2,3,4,1)\), \((3,4,1,2)\), and \((4,1,2,3)\); each contains \(1,2,3,4\) once. The columns are \((1,2,3,4)\), \((2,3,4,1)\), \((3,4,1,2)\), and \((4,1,2,3)\), so each also contains all four symbols once. The completed array is a Latin square.

Worked Example: A Three-Symbol Rectangle with a Forced Last Row

Take the Latin rectangle with symbol set \(\{1,2,3\}\) and rows \((1,2,3)\) and \((2,3,1)\). Column \(c_1\) contains \(1,2\), so only \(3\) is available there. Column \(c_2\) contains \(2,3\), so only \(1\) is available. Column \(c_3\) contains \(3,1\), so only \(2\) is available. Its available-pair graph has column set \(\{c_1,c_2,c_3\}\), symbol set \(\{s_1,s_2,s_3\}\), and edge set \(\{c_1s_3,c_2s_1,c_3s_2\}\). These three edges are a matching covering all vertices, so the added row is \((3,1,2)\).

Check: The rows \((1,2,3)\), \((2,3,1)\), and \((3,1,2)\) each contain all three symbols. Reading down the columns gives \((1,2,3)\), \((2,3,1)\), and \((3,1,2)\), respectively. Hence this is a Latin square of order \(3\). The graph has exactly three edges, and the displayed matching uses all three, independently confirming the assignment covers all columns and symbols.

Worked Example: A Different Four-Symbol Completion

Start with rows \((1,2,3,4)\) and \((3,4,1,2)\). Column \(c_1\) has \(1,3\), leaving \(\{2,4\}\); \(c_2\) has \(2,4\), leaving \(\{1,3\}\); \(c_3\) has \(3,1\), leaving \(\{2,4\}\); and \(c_4\) has \(4,2\), leaving \(\{1,3\}\). Thus the available-pair graph has edge set \(\{c_1s_2,c_1s_4,c_2s_1,c_2s_3,c_3s_2,c_3s_4,c_4s_1,c_4s_3\}\). Choose the matching \(\{c_1s_2,c_2s_1,c_3s_4,c_4s_3\}\), giving row \((2,1,4,3)\).

The four columns now contain \((1,3,2)\), \((2,4,1)\), \((3,1,4)\), and \((4,2,3)\). Their missing symbols are respectively \(\{4\},\{3\},\{2\},\{1\}\), so the final row is forced to be \((4,3,2,1)\). The completed rows are \((1,2,3,4)\), \((3,4,1,2)\), \((2,1,4,3)\), and \((4,3,2,1)\).

Check: Each displayed row is a rearrangement of \(\{1,2,3,4\}\). The columns are \((1,3,2,4)\), \((2,4,1,3)\), \((3,1,4,2)\), and \((4,2,3,1)\), each containing \(1,2,3,4\) exactly once. Thus the array is a Latin square.

Reading and Checking the Choices

The available-pair graph should be recomputed from the current array at every stage. Once a row has been added, some edges disappear: a symbol selected for one column is no longer available there, and each column’s list must be updated using all entries above it. A matching for an earlier stage is not automatically a matching for a later one; it is a new assignment problem.

The proof of the extension theorem gives a useful existence check. With \(k\) rows, every column and every symbol has exactly \(n-k\) available partners. For a nonempty subset \(X\) of columns, counting edges leaving \(X\) gives \((n-k)|X|\); since each neighboring symbol has at most \(n-k\) incident edges in total, this forces \(|N(X)|\ge |X|\). Hall’s theorem then guarantees a full matching. This argument proves that completion is possible, but an actual completion still requires displaying a particular matching, as in the examples.

Common pitfall: choosing independently. In the first four-symbol example, both \(c_1\) and \(c_4\) can individually use symbol \(3\): \(c_1s_3\) and \(c_4s_3\) are edges. Choosing \(3\) for both columns is not a matching, because those two edges share the symbol vertex \(s_3\); it would repeat \(3\) in the new row. The correction is to choose distinct symbol endpoints, for example the matching \(c_1s_3,c_2s_4,c_3s_1,c_4s_2\), which yields \((3,4,1,2)\). Availability for each column separately is not enough; the choices must form one matching.

Check Your Understanding

For each question, distinguish an available pair from a set of pairs that forms a matching.

  1. For the first four-symbol rectangle, list the available symbols in each column before adding the third row.
  2. In the second example, why does a matching covering the three columns necessarily use all three symbols?
  3. Starting with the rows \((1,2,3,4)\) and \((2,1,4,3)\), find the available symbols in each column and give one matching that supplies the next row.
  4. Explain why the degree-counting argument divides by \(n-k\) only when \(k<n\).
  5. State which assumption in the completion corollary guarantees that the first array being extended is already a Latin rectangle.