aa r X i v : . [ m a t h . C O ] A p r Sudoku Rectangle Completion
Mohammad Mahdian Ebadollah S. Mahmoodian ∗ Google ResearchMountain View, CA, USA Department of Mathematical SciencesSharif University of TechnologyTehran, I.R. IRAN
Abstract
Over the last decade, Sudoku, a combinatorial number-placement puzzle, has become a favoritepastimes of many all around the world. In this puzzle, the task is to complete a partially filled 9 × × n . Key Words: Sudoku squares, Latin squares, Number of Sudoku squares, Critical sets in Latin squares.
A Latin square is an n × n matrix with entries in 1 , . . . , n such that each of the numbers 1 to n appearsexactly once in each row and in each column. Latin squares are heavily studied combinatorial objects thatdate back to the time of Euler and probably earlier. A variant of the notion of Latin squares has recentlysurfaced in the form of a number-placement puzzle called Sudoku. In this puzzle, the task is to complete apartially filled 9 × × Latin square of order n is an n × n matrix with entries from [ n ] = { , . . . , n } that satisfies the followingtwo conditions: • row condition : every element in [ n ] appears at most once in each row. • column condition : every element in [ n ] appears at most once in each column.When n = k for an integer k , for every i, j ∈ [ k ], the ( i, j ) th block of an n × n matrix M is defined asthe set of entries with coordinates in (( i − k + x, ( j − k + y ) for x, y ∈ [ k ]. We say that ( i, j ) are thecoordinates of this block. These blocks partition the set of entries in M into k submatrices, each of size ∗ This research is partially supported by a grant from the INSF. × k and therefore containing n entries. The i th row block of M is the union of the blocks at coordinates( i, j ) for j ∈ [ k ]. Similarly, the j th column block of M is the union of the blocks at coordinates ( i, j ) for i ∈ [ k ]. A Sudoku square of order n = k is an n × n matrix that in addition to the row and column conditionsabove, satisfies the following condition: • block condition : every element in [ n ] appears at most once in each block.A partial Latin (Sudoku) square of order n is an n × n matrix with entries from [ n ] ∪{∗} (with ∗ representingan empty entry) that satisfies the row and column (row, column, and block) conditions. A partial Latin(Sudoku) square P is an extension of a partial Latin (Sudoku) square P if they have the same order and forevery ( i, j ) ∈ [ n ] , if P ( i, j ) = ∗ , then P ( i, j ) = P ( i, j ). For m < n , an m × n Latin (Sudoku) rectangle isan n × n partial Latin (Sudoku) square in which all cells in the first m rows are filled and all remaining cellsare empty. More generally, for every p, q ≤ n , a ( p, q, n )-Latin (Sudoku) rectangle is an n × n partial Latin(Sudoku) square in which all cells in the intersection of the first p rows and the first q columns are filled andall remaining cells are empty.For Latin rectangles there is a well-known theorem of Marshal Hall [6] that states: Every m × n Latinrectangle can be extended to an n × n Latin square. This theorem is proved by using the classical matchingtheorem of Philip Hall. A natural question is whether the similar statement holds for Sudoku rectangles.In this paper, we study this question, and will show that, perhaps surprisingly, the answer depends on thevalue of m .For n = 9 (the regular Sudoku), this question was answered by Kanaana and Ravikumar [8]. Theyshowed that for all values of m except m = 5, an m × m = 5, this is not always possible. For example, see the 5 × , . . . , ⋆ Figure 1: A 5 × n , the only previous result on completability of Sudoku rectangle is the following theoremproved by Kanaana and Ravikumar [8]. Theorem A. ([8])
Assume n = k and n − k ≤ m < n . Then every m × n Sudoku rectangle can be completedto a Sudoku square.
In this paper, we prove two more sufficient conditions for m , under which every m × n Sudoku rectangle iscompletable to an n × n Sudoku square (Section 2). These results are proved using a two-stage procedure forcompleting a Sudoku rectangle, where generalized matching and bipartite graph edge coloring is used withinthe two stages. We will show in Section 3 that the union of these three conditions is a full characterization ofthe values of m for which every m × n Sudoku rectangle is completable. An important ingredient of this proofis a constructive lemma that shows how to generalize a non-completable m × k Sudoku rectangle to a non-completable m × n Sudoku rectangle. Sections 4 and 5 are devoted to two corollaries of our characterization.We observe in Section 4, that the procedure used to prove our sufficient conditions gives an efficient algorithmfor deciding whether a given m × n rectangle is completable and find a valid completion. Furthermore, inSection 5 we use this procedure combined with theorems of Minc and Van der Waerden, to prove asymptoticbounds on the number of Sudoku squares of order n . 2 elated work. Recently quite a few papers have appeared on the mathematical questions raised forSudoku squares similar to Latin squares. For example in [4] the number of Sudoku squares is discussed, whilesome results about the sets of mutually orthogonal Sudoku squares are given in [11]. Concepts of “critical(or defining) sets” i.e. “the minimum Sudoku problem” and “Sudoku trades (or detection of unavoidablesets in Sudoku)” are studied in [9], [10], [14], and [3]. In [1] Sudoku is considered as a special case ofGerechte designs and they introduce some interesting mathematical problems about them. The complexityand completeness of finding solution for Sudoku is investigated in [12]. List coloring of Latin and Sudokugraphs is studied in [7] which has an extensive number of references on Sudoku. In [8] the problem ofcompleting Sudoku rectangles is studied.
In Theorem A it is shown that if the Sudoku rectangle only leaves parts of the last row block incomplete,then it can be completed to a Sudoku square. In this section, we prove two theorems, showing that forcertain other values of m , an m × n Sudoku rectangle can always be completed to a Sudoku square. Westart with the next result which shows that if the Sudoku rectangle consists of a number of full row blocksand a number of empty row blocks (i.e., no row block is partially filled), then it can always be completed toa Sudoku square.
Theorem 1.
Assume n = k and m = lk for some l < k . Then every m × n Sudoku rectangle R can becompleted to a Sudoku square.Proof. We prove that we can complete the rectangle R row-block by row-block. To do this, we need toshow that R can be extended to a k ( l + 1) × n Sudoku rectangle. This is done in two steps: First, we fillthe elements in the ( l + 1)st row block in such a way that column and block conditions are satisfied. Inthe second step, we permute the elements in each column of the ( l + 1)st row block in such a way that theresulting configuration satisfies the row condition as well. Note that column and block conditions will staysatisfied after such a permutation, and therefore, the resulting configuration is a valid Sudoku extension of R . We start with the first step. The ( l +1)st row block consists of k blocks, which we denote by B , B , . . . , B k .For each block B d , we formulate an assignment problem as follows: On one side of the assignment problem,we have the numbers 1 , . . . , n . On the other side, we have the k columns c , c , . . . , c k of the block. Anumber i can be assigned to a column j , if i does not appear in column j in R . For each number i , thisnumber appears exactly once in each of the blocks above B d , and these appearances are in different columns.Therefore, each number i can be assigned to exactly k − l different columns. Also, for each column j , thereare precisely lk distinct numbers in that column in R . Therefore, there are precisely n − lk numbers thatcan be assigned to column j . The objective is to find an assignment that assigns each number to exactlyone column, and assigns precisely k numbers to each column.We show that this assignment problem always has a feasible solution. We prove this by using a networkflow argument. The assignment problem can be formulated as a network flow problem: There is a source s that has links of capacity 1 to n nodes representing the numbers; each number i has a link of capacity 1to each of the nodes representing columns that it can be assigned to; and there is a sink t that has a linkof capacity k from each of the nodes representing the columns. It is easy to see that it is possible to routea flow of value n from s to t in this network: The flow on each of the edges from s to number nodes is 1;the flow on each of the edges from number nodes to column nodes is 1 / ( k − l ); and the flow from each ofthe column nodes to t is k . It is not hard to see that this is a feasible flow of value k (and is therefore themaximum flow from s to t ). By the Ford-Fulkerson theorem, there must be an integer flow of the same valuein this network. This integer flow gives an assignment of numbers 1 , . . . , n to the k columns in B d such thateach number is assigned to precisely one column, each column has precisely k numbers assigned to it, andno number is assigned to a column c i where it appears in the i th column of R . Putting these assignments3ogether for all blocks B d of the ( l + 1)st row block, we obtain an assignment of the n numbers to the n columns such that: • each number is assigned to precisely k columns, one from each block; • each column has precisely k numbers assigned to it; and • no number is assigned to a column where it appears in one of the cells of the column above that.Let us call this assignment M . The second step is to take the assignment M and specify in which of the k rows of the ( l + 1)st row block each number must go. We construct a bipartite graph as follows: On oneside, we have the numbers 1 , . . . , n , and on the other side, we have the n columns of the ( l + 1)st row block.There is an edge between number i and column j , if i is assigned to j under the assignment M . By theproperties of M , this is a bipartite k -regular graph. By K¨onig’s theorem, this graph has an edge-coloringwith k colors. Let the colors be denoted by 1 , . . . , k . We now complete the ( l + 1)st row block as follows: Foreach edge ( i, j ) colored with color c , we place the number i on the c th row of the row block and j th column.It is easy to see that with the addition of this row-block all the Sudoku conditions are still satisfied: Thereis no repeated element in any row, since the coloring is a proper edge coloring; there is no repeated elementin each column by the third property of the assignment M ; and there is no repeated element in each blockby the first property of the assignment M .Next, we prove the following sufficient condition for completability of a Sudoku rectangle. Theorem 2.
Assume n = k and m = lk + r for some l < k and ≤ r < k . Then an m × n Sudokurectangle R can always be completed to a Sudoku square, if ( k − r )( k − l ) ≥ lk .Proof. We proceed the same way as in the proof of Theorem 1. The empty rows of the ( l + 1)st row blockform a ( k − r ) × n rectangle R . First, we show that for each column in R , we can pick k − r distinctelements in such a way that the elements chosen for the columns in each block are distinct, and the k − r elements for each column do not appear in that column in R . Next, we show that the elements in eachcolumn can be permuted in such a way that the elements in each row become distinct. Note that for thesecond step exactly the same proof as in Theorem 1 works. Therefore, we only need to prove the first step.Also, note that the first step can be done block-by-block. So, it is enough to consider one block B d , andprove the following: for each column in B d we can pick k − r elements distinct from elements that appear in B d and in the cells of the same column above B d in such a way that the elements picked for the k columnsin B d are distinct.We formulate the problem as a matching problem as follows: On one side, we have k vertices correspondingto the k columns in the block B d . We call these the column vertices. On the other side, we have n − rk vertices, corresponding to the elements that do not appear in the r filled rows of the block. We call thesethe element vertices. There is an edge between a column vertex and an element vertex if the correspondingelement does not appear in the corresponding column in R . The degree of each element vertex is precisely k − l , since out of the k columns, it appears in l of them (one for each block above this block). The degreeof each column vertex is a number between n − lk − rk and n − lk . We prove that there is a 1-to-( k − r )matching in this graph, i.e., a matching which matches each column vertex to precisely k − r element vertices,and each element vertex to precisely one column vertex.We prove this by verifying the following easy extension of Hall’s condition [13] for the existence of a 1 to( k − r ) matching. This condition states that such a matching exists if and only if for every set S of columnvertices, | N ( S ) | ≥ ( k − r ) | S | , where N ( S ) is the set of all element vertices adjacent to at least one vertex in S . To prove this, we consider two cases: either | S | > l or | S | ≤ l . In the first case, consider an element x thatdoes not appear in the r filled rows of the block. Since x appears in exactly l columns in the correspondingcolumn block in R and | S | > l , there is at least one column in S that does not contain x . Therefore, thecorresponding column vertex is adjacent to the element vertex x . This means that in this case, N ( S ) is theset of all n − rk element vertices. Hence, | N ( S ) | = k ( k − r ) ≥ | S | ( k − r ), as desired. In the second case4 | S | ≤ l ), we use the fact that the degree of each column vertex in this graph is at least n − lk − rk , andtherefore, | N ( S ) | ≥ n − lk − rk . Using this inequality, we have: | N ( S ) | ≥ k − lk − rk = ( k − r )( k − l ) − rl ≥ lk − rl ≥ ( k − r ) | S | . This completes the proof of Hall’s condition, which implies that to each column we can assign k − r elements distinct from elements that appear in the r filled rows of the block, such that each such element isassigned precisely to one column. In this section, we give some Sudoku rectangle constructions to prove that the union of the three sufficientconditions given in Section 2 and Theorem A is also necessary.
Theorem 3.
Assume n = k and m = lk + r for some l < k and ≤ r < k . Every m × n Sudoku rectangle R can always be completed to a Sudoku square, if and only if at least one of the following conditions hold: • l = k − , • r = 0 , or • ( k − r )( k − l ) ≥ lk . We proved sufficiency of the above conditions in the previous section. To prove necessity, we need toconstruct an m × n Sudoku rectangle that is not completable for any value of m that does not satisfy theconditions of the theorem. The main tool we use in this construction is the following extension of Theorem 1,which proves that any ( m, k, n )-Sudoku rectangle can be extended to an m × n Sudoku rectangle. This meansthat to construct an m × n Sudoku rectangle that is not completable, it is enough to construct its first columnblock, i.e., an ( m, k, n )-Sudoku rectangle that is not completable.
Lemma 1.
For every n = k , m ≤ n , every ( m, k, n ) -Sudoku rectangle R can be extended to an ( m, n, n ) -Sudoku rectangle.Proof. We follow an algorithm similar to the one used in the proof of Theorem 1 to extend R , column blockby column block. Before starting this algorithm, first we append a few rows to R to make sure the numberof rows is a multiple of k : Let m = lk + r , where 0 ≤ r < k . We append k − r rows to R , containingthe n − rk elements that do not appear in rows lk + 1 through lk + r in R in an arbitrary order. Thisconverts R into an ( l + 1) k × k rectangle R ′ that satisfies the row and block conditions, but might violatethe column condition (i.e., R ′ is not necessarily a partial Sudoku square). Now, we append a new columnblock to this rectangle using a two-stage process as follows: In the first stage, for each row in R ′ , we aregoing to pick k elements among elements that do not already appear in this row in R ′ , such that sets pickedfor rows within the same row block are disjoint. This is done by constructing a graph similar to the oneconstructed in the proof of Theorem 1 for each row block of R ′ , and proving it contains a k -to-1 matching.The graph contains k row vertices corresponding to the rows within this row block, and n element verticescorresponding to the elements 1 to n . There is an edge between row vertex i and element vertex j if j doesnot appear in the i th row of R ′ . Since R ′ satisfies row and block constraints, the degree of each row vertexin this graph is precisely n − k and the degree of each element vertex is k −
1. Therefore, using essentiallythe same argument as in the proof of Theorem 1, we can show that this graph contains a matching thatmatches each row vertex to precisely k element vertices and each element vertex to exactly one row vertex.In the second stage, we assign each of the k elements assigned to each row to one of the k columns withinthe new column block, in such a way that the column condition is satisfied. Again, this is done by buildinga bipartite graph as in the proof of Theorem 1. The graph contains ( l + 1) k row vertices, corresponding to5he rows of R ′ , and n element vertices. There is an edge between an element vertex i and a row vertex j ifthe element i is assigned to the row j in the first stage. The maximum degree of vertices in this graph is k .Therefore, the graph is k -edge colorable. We assign each color to one column of the new column block, andplace an element i in row j in column c of this column block, if the edge between i and j is colored with thecolor corresponding to c . This ensures that the vertices assigned to the same column are distinct. Therefore,we obtain an ( l + 1) k × k extension of R ′ that satisfies block and row conditions, and satisfies the columnconditions except possibly for the first k columns. We can continue this process, column block by columnblock, resulting in an ( l + 1) k × n extension of R ′ that satisfies row and block conditions and the columnconditions except possibly for the first k columns (i.e., columns of R ′ ). Removing the last k − r rows of thisrectangle results in an m × n rectangle that satisfies row, block, and column conditions.The following lemma is another useful tool in our constructions. Lemma 2.
For every a, b ≤ k and every set A of k · max { a, b } elements, there is an ( ak, b, n ) -Sudokurectangle with elements from A .Proof. Let c = max { a, b } . We partition the elements of A into c sets A , A , . . . , A c − , each of size k . TheSudoku rectangle is constructed as follows: We fill the elements in column j + 1 (0 ≤ j < b ) and rows ik + 1through ik + k (0 ≤ i < a ) of the rectangle with elements from A ( i + j ) mod c , in increasing order . Sincefor any fixed i , the family { A ( i + j ) mod c : 1 ≤ j ≤ b } is a family of disjoint sets, the block conditions (andtherefore the row conditions) are satisfied. Also, for every fixed j , the family { A ( i + j ) mod c : 1 ≤ i ≤ a } is afamily of disjoint sets, and therefore the column conditions are also satisfied.Equipped with the above lemmas, we are now ready to prove Theorem 3: Proof of Theorem 3.
The “if” part follows from Theorems A, 1, and 2. To prove the “only if” part, let m = lk + r be a number that does not satisfy any of the three conditions (i.e., l ≤ k − r ≥
1, and( k − r )( k − l ) < lk ), and construct an m × n Sudoku rectangle that cannot be completed to a Sudoku square.We use Lemma 1 in this construction as follows: Instead of constructing an m × n Sudoku rectangle, weconstruct an ( m, k, n )-Sudoku rectangle that cannot be completed into a Sudoku square, and use Lemma 1to extend this m × k rectangle to an m × n rectangle. As the original m × k rectangle was not completable,the m × n rectangle cannot be completable either.We consider three cases for this construction: (a) l < k/
2, (b) l ≥ k/ k is even, and (c) l ≥ k/ k is odd.(a) l < k/
2: Using Lemma 2 with a = b = l , we can construct an ( lk, l, n )-Sudoku rectangle R withentries in { , . . . , lk } . Also, since l + 1 ≤ k − l , using Lemma 2 with a = l + 1 and b = k − l we obtainan (( l + 1) k, k − l, n )-Sudoku rectangle R with elements in { lk + 1 , . . . , k } . The idea is to constructan ( m, k, n )-Sudoku rectangle by concatenating the columns of R after the columns of R . However, R has m − r rows and R has m + k − r rows, and therefore before concatenating R and R , we needto add r rows to R and remove k − r rows from R to make sure both rectangles have m rows. To dothis, we first simply remove the extra k − r rows from R . These rows contain a set of ( k − r )( k − l )elements E . We place these elements in an arbitrary order in the missing r rows of R . To fill theserows with elements in E , we need lr ≤ | E | = ( k − r )( k − l ) = lr + k ( k − l − r ). This holds if and onlyif l + r ≤ k , in which case we are done. If l + r > k , R is still missing lr − | E | = k ( l + r − k ) elementsto become an m × l rectangle. We pick a set E ′ of this many elements arbitrarily from rows lk + 1through lk + r of R . This is feasible, since R has ( k − l ) r elements in these rows, and( k − l ) r = ( r + l ) k − ( r + k ) l > ( r + l ) k − ( k + k ) l > ( r + l ) k − k · k k ( l + r − k ) . For the purpose of this lemma, elements of A ( i + j ) mod c can be placed in any arbitrary order. However, placing them inincreasing order makes it easier to combine and modify these rectangles, as needed in the proof of Theorem 3.
6e now perform the following switch: The elements of E ′ in the rows lk + 1 through lk + r of R are replaced with arbitrary elements in 1 , . . . , lk } (possible since k ( l + r − k ) ≤ lk ), and the missingelements of R are filled with elements in E ′ .It is easy to see that the rectangle R obtained by concatenating the columns of R and R after theabove operations is an ( m, k, n )-Sudoku rectangle: The block conditions are satisfied since R and R initially satisfied these conditions, they were composed of disjoint sets of elements, and none of thesteps above violated the block condition. The row conditions follows directly from the block conditions,and the column conditions are also true since they are true for R and R constructed by Lemma 2,and the above operations only moved elements from lk + 1 , . . . , k to the first l columns (which didnot previously contain any of these elements), and elements from 1 , . . . , lk to the last k − l columns(which, again, did not previously contain any of these elements).Now, we prove that R is not completable to a Sudoku square. We consider two cases: l + r ≤ k and l + r > k . In the latter case, it is evident from the above construction that all elements in { lk +1 , . . . , k } appear in the last partial block (i.e., last r rows) of R . Also, all elements in { , . . . , lk } appear in eachof the first l columns. Therefore, there is no element that can be placed in any of the entries in columns1 through l of the ( m + 1)st row without violating column or block conditions.We now consider the case l + r ≤ k . Consider the first l columns of R . To complete R , we must fillrows m + 1 , . . . , m + k − r = ( l + 1) k of these columns with l ( k − r ) elements. Let us call the setof these elements S . By block conditions, elements in S must all be distinct, and also distinct fromthe rk elements in the first r rows of this block. Furthermore, since all elements in { , . . . , lk } appearin each of the first l columns, by column conditions S cannot contain any of the elements 1 , . . . , lk .Therefore, we must have at least l ( k − r ) + rk + lk distinct elements. Thus, l ( k − r ) + rk + lk ≤ k , or lk ≤ k − lk − rk + lr = ( k − l )( k − r ), contradicting the third condition.(b) l ≥ k/ k is even: Let F = { , . . . , k } and G = { k + 1 , . . . , k } . We use Lemma 2 to constructthe following four Sudoku rectangles: • a ( k , k , n )-Sudoku rectangle R with entries in F , • a ( k , k , n )-Sudoku rectangle R with entries in G , • an (( l + 1 − k ) k, k , n )-Sudoku rectangle R with entries in G , and • an (( l + 1 − k ) k, k , n )-Sudoku rectangle R with entries in F .Recall that the construction in Lemma 2 starts by defining a partition of the set of elements into subsetsof size k . Let F , F , . . . , F k/ − be the partition of F used to construct R , and G , G , . . . , G k/ − be the partition of G used to construct R . To construct R , we use this permutation of the latterpartition: G , G , G , . . . , G k/ − , G , G . In other words, the first column of the first row block of R contains elements of G , the second column of this row block contains elements of G , the third columncontains G , and so on. For R , we use the partition F k/ − , F k/ − , . . . , F , F . By placing the fourrectangles R , R , R , and R in the following configuration, we obtain an ( l + 1) k × k rectangle R : R = (cid:20) R R R R (cid:21) It is easy to see that R is a Sudoku rectangle. Next, we remove the last k − r rows of R to obtain an( m, k, n )-Sudoku rectangle R ′ .Since the partition G , G , G , . . . , G k/ − , G , G was used to construct R , in the first column of thisrectangle elements of these sets appear in this order. Since R contains l + 1 − k < k row blocks, noneof the elements of G can appear in the first column of R (and thereofre in the first column of R ′ ).Similarly, none of the elements of G appear in the last column of R (and therefore the k th columnof R ′ . The first column of R contains elements of F k/ − , F k/ − , . . . , in this order. Thus, the first7olumn of R (and therefore the ( k + 1)th column of R ′ ) does not contain any of the elements of F .In the second column of R , we have elements of F k/ − , F k/ − , . . . , in this order. If l < k −
2, noneof the elements of F appear in this column (and therefore the ( k + 2)th column of R ′ ). If l = k − F appear in the last row block in the second column of R . But then since R ′ is obtainedfrom R by removing its last k − r > last element of F does not appear in the ( k + 1)thcolumn of R ′ . Let x denote the last element of F , x denote the last element of G , and x denotethe last element of G . By the above arguments, we know that x does not appear in ( k + 1)th and( k + 2)th columns of R ′ , x does not appear in its first column, and x does not appear in its k thcolumn. Also, by the construction of R and R , x appears in the first column of the first row blockand the k th column of the second row block of R ′ , x appears in the ( k + 1)th column of the first rowblock of R ′ , and x appears in the ( k + 2)th column of the second row block of R ′ . Finally, since x ,and x are the last elements of the sets G and G , they can only appear in the last row in any rowblock in R . Therefore, since R ′ is obtained from R by removing the last k − r ≥ x nor x appear in the last row block of R ′ .We now perturb the rectangle R ′ to obtain another rectangle that is not completable. We do this byfirst swapping x and x in the first row block of R ′ , and x and x in the second row block of R ′ . Bythe above observations, these swaps do not violate the Sudoku conditions. Furthermore, after theseswaps, the ( k + 1)th column of the rectangle does not contain x and its ( k + 2)th column does notcontain x . Therefore, we can change the element in row lk + 1 and column ( k + 1) to x , and theelement in row lk + 1 and column ( k + 2) to x . Again, it is easy to see that Sudoku conditions arepreserved. Let R ′′ denote the resulting ( m, k, n )-Sudoku rectangle.We argue that R ′′ is not completable. Consider the first k/ R ′′ . To complete R ′′ , we mustplace k ( k − r ) distinct elements in rows m + 1 , . . . , m + k − r = ( l + 1) k of these columns. Let T denotethe set of these elements. Every element in F \ { x } appears in each of the first k/ R ′′ .Therefore, T cannot contain any elements of F , except possibly x . Also, it cannot contain any of theelements of G that appear in the last row block of R ′′ . There are precisely r · k + 2 such elements,namely the r · k elements of G that appear in the first k/ R ′′ , and x and x . This means that there are at most k ( k − r ) − G that can be in T . Therefore, T cannot contain more than k ( k − r ) − l ≥ k/ k is odd: The high-level idea of the construction is similar to the one in case (b): weconstruct an ( l + 1) k × k rectangle R by composing four smaller rectangles, truncate it to get an m × k rectangle R ′ , and then slightly perturb it to get an m × k rectangle R ′′ that is not completable.Let F = { , . . . , k ⌈ k ⌉} , G = { k ⌈ k ⌉ + 1 , . . . , k } , and H = { k + 1 , . . . , k + k } . Note that | F | = k ⌈ k ⌉ , | G | = k ⌊ k ⌋ , and | G ∪ H | = k ⌈ k ⌉ . We construct the following Sudoku rectangles using Lemma 2: • a ( k ⌈ k ⌉ , ⌊ k ⌋ , n )-Sudoku rectangle R with entries in F , • a ( k ⌈ k ⌉ , ⌈ k ⌉ , n )-Sudoku rectangle R with entries in G ∪ H . • an (( l + 1 − ⌈ k ⌉ ) k, ⌊ k ⌋ , n )-Sudoku rectangle R with entries in G , and • an (( l + 2 − ⌈ k ⌉ ) k, ⌈ k ⌉ , n )-Sudoku rectangle R with entries in F .Recall that the construction in Lemma 2 starts by defining a partition of the set of elements into subsetsof size k . Let F , F , . . . , F ⌈ k/ ⌉− be the partition of F used to construct R , and H, G , G , . . . , G ⌊ k/ ⌋− be the partition of G ∪ H used to construct R . Without loss of generality, we assume that the partition G ⌊ k/ ⌋− , G ⌊ k/ ⌋− , . . . , G is used to construct R , and the partition F ⌈ k/ ⌉− , F ⌈ k/ ⌉− , . . . , F , F isused to construct R . This means that the first row block of R contains elements of F in its firstcolumn, F in the second column, and F ⌈ k/ ⌉− in its last (i.e., ⌊ k/ ⌋ th) column. Therefore, the firstrow block of R does not contain any of the elements of F ⌈ k/ ⌉− . Similarly, the second row block of R does not contain any element in F , the third row block does not contain any element in F , and so8n. We now modify R as follows: Replace elements of H in the first row block of R by elements of F ⌈ k/ ⌉− , the elements of H in the second row block of R by elements of F , and so on. Let R ′ denotethe resulting rectangle. All entries of R ′ are in F ∪ G . Note that by the construction in Lemma 2,elements of H appear in the first column of R in the first row block, the last (i.e., ⌈ k/ ⌉ th) columnin its second row block, . . . , and the second column in its last (i.e., ⌈ k/ ⌉ th) row block. This meansthat the set of elements appearing in the first column of R ′ is G ∪ F ⌈ k/ ⌉− , in its second column is G ∪ F ⌈ k/ ⌉− , and so on. On the other hand, the set of elements appearing in the i ’th column of thefirst row block of R is precisely F ⌈ k/ ⌉− i . Therefore, if we remove the first row block of R , we obtainan (( l + 1 − ⌈ k ⌉ ) k, ⌊ k ⌋ , n )-Sudoku rectangle R ′ with elements in F such that the i ’th column of R ′ does not contain any of the elements of F ⌈ k/ ⌉− i . We are now ready to define an ( l + 1) k × k rectangle R by placing the four rectangles R , R ′ , R , and R ′ as follows: R = (cid:20) R R ′ R R ′ (cid:21) Given the above construction, it is easy to see that R is a Sudoku rectangle with elements in F ∪ G .Let R ′ denote the ( m, k, n )-Sudoku rectangle obtained by removing the last k − r rows of R . Thelast step is to perturb R ′ by moving a few elements in such a way that the resulting rectangle is notcompletable.Recall that the partition G ⌊ k/ ⌋− , G ⌊ k/ ⌋− , . . . , G was used to construct R . Therefore, in the firstcolumn of R , we have the elements in G ⌊ k/ ⌋− , G ⌊ k/ ⌋− , . . . , G s , where s = ⌊ k/ ⌋ − ( l + 1 − ⌈ k ⌉ ) = k − − l >
0. Therefore, none of the elements in G appears in the first column of R , and thereforein the first column of R ′ . Similarly, none of the elements of G ⌊ k/ ⌋− appears in the second column of R ′ . In the last column of R , we have the elements of F , F ⌈ k/ ⌉− , F ⌈ k/ ⌉− , . . . , F s +1 . Therefore, noneof the elements of F appears in the last column of R ′ . In the first column of R , we have elementsof F ⌈ k/ ⌉− , F ⌈ k/ ⌉− , . . . , F s . Therefore, since R ′ is obtained by removing the last k − r ≥ R , the last element of F does not appear in the ⌈ k/ ⌉ th column of R ′ (which corresponds to the firstcolumn of R ). Now, let x denote the last element of F , x denote the last element of G ⌊ k/ ⌋− ,and x denote the last element of G . To summarize, the above arguments, we know that x does notappear in neither the last nor the ⌈ k/ ⌉ th column of R ′ , x does not appear in the second column of R ′ , and x does not appear in the first column of R ′ . Furthermore, by the definition of R and R , x appears in the second column of the first row block of R ′ and the first column of the second row blockof R ′ (where all elements of F are listed), x appears in the last column of the first row block of R ′ (where all the elements of G ⌊ k/ ⌋− are listed), and x appears in the ⌈ k/ ⌉ th column of the secondrow block of R ′ (where all the elements of G are listed). Finally, since x and x are the last elementsof G ⌊ k/ ⌋− and G , they can only appear in the last row in any row block in R . Therefore, since R ′ isobtained from R by removing the last k − r ≥ x nor x appear in the last row blockof R ′ .We are now ready to perform the swaps that would make R ′ not completable. In the first row blockof R ′ , we swap x and x (which appear in the second and the last columns). In the second row block,we swap x and x (occuring in the first and the ⌈ k/ ⌉ th column). By the above observations, theseswaps do not violate the Sudoku conditions. After these swaps, there is no x in the last column ofthe rectangle. Therefore, we can replace the element in the row lk + 1 of this column by x . Similarly,we can replace the element in the row lk + 1 of the ⌈ k/ ⌉ th column by x . Let R ′′ denote the resulting( m, k, n )-Sudoku rectangle.We now prove that R ′′ is not completable. To see this, consider the first ⌊ k/ ⌋ columns, and noticethat to complete R ′′ , we need to place ( k − r ) ⌊ k/ ⌋ distinct elements in rows m + 1 through m + k − r of these columns. Let T denote the set of these elements. Since all elements in F \ { x } appear ineach of the first ⌊ k/ ⌋ columns of R ′′ , we must have T ⊆ G ∪ { x } . On the other hand, by the blockcondition, none of the elements in T must appear in the last row block of R ′′ . This row block containsprecisely r ⌊ k ⌋ elements of G in its first ⌊ k/ ⌋ columns and two elements of G (namely, x and x ) in9he remaining columns. Therefore, T cannot contain more than ( k − r ) ⌊ k/ ⌋ − The two-stage procedure used in the proof of Theorem 2 is essentially a polynomial-time algoritm for com-pleting a Sudoku rectangle into a Sudoku square. Furthermore, we note that the same procedure applies forevery value of m , and not just for those for which Theorem 2 guarantees the existence of a Sudoku square.This is a simple observation, and follows from the fact that if the given Sudoku rectangle R has a validextension, then this extension gives a perfect 1-to-( k − r ) matching in the graph constructed in the firststage. On the other hand, if R is not completable, then the graph constructed in the first stage does nothave any perfect 1-to-( k − r ) matching, since if it did, this matching can be turned into an extension to aSudoku square using the method outlined in the proof of Theorem 2. Therefore, we have the following result. Theorem 4.
There is a polynomial time algorithm that given an m × n Sudoku rectangle R , finds a completionof R to a Sudoku square, or decides that R is not completable to a Sudoku square. An interesting follow-up question is whether the above result can be generalized to the case where R is ageneral partial Sudoku square or when R is a ( p, q, n )-Sudoku rectangle. We conjecture that at least in theformer case, the problem is NP-complete. Let Sud( n ) denote the number of Sudoku squares of order n . In this section, we give a tight asymptoticbound on (Sud( n )) /n . Our proof uses the Sudoku rectangle completion procedure of the Section 3 as wellas classical bounds on the permanent of matrices. Our result is summarized in the following theorem. Theorem 5.
We have (Sud( n )) /n ∼ e − n as n → ∞ . This should be contrasted with a similar result for Latin squares (see, for example, [13, Theorem 17.3]),which shows that ( L ( n )) /n ∼ e − n as n → ∞ , where L ( n ) is the number of Latin squares of order n . Inother words, Corollary 1.
The fraction of the Latin squares of order n that are Sudoku squares is ( e + o (1)) n . Proof of Theorem 5 uses two classical results about the permanent of matrices. The first result, knownas the Van der Waerden conjecture (proved independently by Falikman and Egoritsjev, see [13]), states thatthe permanent of every doubly stochastic matrix of order n is at least n ! n − n . This implies Theorem B. ([13])
The number of perfect matchings in an r -regular bipartite graph with n vertices in eachpart is at least n !( r/n ) n . The other result is an upper bound on the permanent of matrices. This result, conjectured by Minc in 1967and proved by Br´egman in 1973, shows that the permanent of a (0 , r , r , . . . , r n isat most Q j ( r j !) /r j . This implies Theorem C. ([13])
The number of perfect matchings in an r -regular bipartite graph with n vertices in eachpart is at most ( r !) n/r . m ( n, r ) and M ( n, r ) denote the minimum and the maximum of the number of perfect matchings inan r -regular bipartite graph with n vertices in each part. Theorems B and C can be written as n !( r/n ) n ≤ m ( n, r ) ≤ M ( n, r ) ≤ ( r !) n/r . We are now ready to prove Theorem 5.
Proof of Theorem 5.
We use the Sudoku rectangle completion procedure of Section 3 to build a Sudokusquare row-block by row-block, and count the number of ways each row-block can be completed. Assumewe are at a stage that l − l throw-block can be completed.To complete the l th row-block, we first process the blocks in this row-block one by one, and for eachblock, solve a matching problem to assign an unordered set of k elements to each column, in such a waythat each element is assigned to only one column within the block, and an element that is assigned to acolumn does not appear in the first ( l −
1) row-blocks in that column. In the proof of Theorem 1, we did thisby formulating an assignment problem with n vertices (corresponding to the elements) on one side and k vertices (corresponding to the columns) on the other side, and finding an assignment that assigns k elementsto each column. To count the number of such assignments, we formulate this as a matching problem byreplacing each column vertices by k copies. The assignments in the original graph correspond to perfectmatchings in this new graph. This graph has n vertices on each side and is ( n − k ( l − m ( n, n − k ( l − M ( n, n − k ( l − k !. This means that the total number ofassignments of k elements to each column, for each block in this row-block, is between m ( n, n − k ( l − k !) k and M ( n, n − k ( l − k !) k . The total number of assignments for all blocks of this row-block is the above value raised to the power k .Next, we count the number of ways each of the k elements assigned to the column can be assigned tothe k rows of this column in a way that no row contains repeated elements. We do this row by row, byconstructing a matching problem for each row. For the first row of the row-block, the graph consists of n nodes corresponding to the n elements on one side and n nodes corresponding to the n columns on the otherside. Each column node is connected by an edge to each of the k elements assigned to it in the first stage.It is easy to see that this is a k -regular graph. Each perfect matching in this graph gives a way to assignelements to the first row of the l th row-block. The number of such perfect matchings is between m ( n, k ) and M ( n, k ). For the next row, we have the same graph, except the element already assigned to the first row isno longer connected to the corresponding column. The graph is ( k − m ( n, k − M ( n, k −
1) perfect matchings. Continuing this process, we show that the number of ways to assign theelements to rows in this row-block is between m ( n, k ) · m ( n, k − · · · m ( n,
1) and M ( n, k ) · M ( n, k − · · · M ( n, . To obtain a minimum and maximum for the total number of Sudoku squares, we multiply the abovevalues for all l = 1 , . . . , k . This gives the following bounds on the total number of Sudoku squares of order n : Sud( n ) ≥ k Y l =1 (cid:20) m ( n, n − k ( l − k !) k (cid:21) k · k Y r =1 m ( n, r ) ! k . (1)11ud( n ) ≤ k Y l =1 (cid:20) M ( n, n − k ( l − k !) k (cid:21) k · k Y r =1 M ( n, r ) ! k . (2)Using Theorem B and inequality (1), we have:Sud( n ) ≥ k Y l =1 (cid:20) n !( n − k ( l − n k ! k n n (cid:21) k · k Y r =1 ( n !( r/n ) n ) ! k = n ! n k ! kn · k n k Y l =1 ( k − ( l − kn · n ! n n n k Y r =1 r kn = n ! n k ! kn k ! kn · k n · n ! n k ! kn n n = n ! n k ! kn k n n n . Using Stirling’s formula, we have n ! > ( n/e ) n and k ! > ( k/e ) k . Therefore,Sud( n ) ≥ n n e − n k n e − n k n n n = ( n/e ) n . Similarly, using Theorem C and inequality (2), we have:Sud( n ) ≤ k Y l =1 (cid:20) ( n − k ( l − n/ ( n − k ( l − ( k !) k (cid:21) k · k Y r =1 r ! n/r ! k . We use the following extension of Stirling’s formula [5] that holds for every x : x ! < ( x/e ) x √ πx · e / (12 x ) . For x ≥ √ π · e / (12 x ) <
3, and therefore, x ! < x/e ) x √ x . Using this inequality, we have:12ud( n ) ≤ k ! kn k Y l =1 ( n − k ( l − kn/ ( n − k ( l − · k Y r =1 r ! kn/r < k ! kn k Y l =1 (cid:18) n − k ( l − e (cid:19) n − k ( l − p n − k ( l − ! kn/ ( n − k ( l − · k Y r =1 (cid:0) r/e ) r √ r (cid:1) kn/r = 1 k ! kn k Y l =1 (cid:18) k ( k − ( l − e (cid:19) kn · k Y l =1 (cid:16) p n − k ( l − (cid:17) n/ ( k − ( l − · k Y r =1 ( r/e ) kn · k Y r =1 (cid:0) √ r (cid:1) kn/r = k n k ! kn k ! kn e n · k Y r =1 (cid:16) √ rk (cid:17) n/r · k ! kn e n · k Y r =1 (cid:0) √ r (cid:1) kn/r = k n k ! kn e n · k Y r =1 (cid:0) (9 r ) k k (cid:1) n/ (2 r ) < k n (3( k/e ) k √ k ) kn e n · k Y r =1 (cid:0) (9 r ) k k (cid:1) n/ (2 r ) = n n e n · (3 √ k ) kn · k Y r =1 (cid:0) (9 r ) k k (cid:1) n/ (2 r ) . Therefore, (Sud( n )) /n < ne · (3 √ k ) /k · k Y r =1 (cid:0) (9 r ) k k (cid:1) / (2 rn ) . (3)All that remains is to prove that (3 √ k ) /k · Q kr =1 (cid:0) (9 r ) k k (cid:1) / (2 rn ) = 1 + o (1). We use the inequalitythat for x < e x < x . Therefore,(3 √ k ) /k = e ln(3 √ k ) k < √ k ) k = 1 + o (1) . (4)Also, using the bound P kr =1 1 r < k ) on the harmonic series, we obtain k Y r =1 (cid:0) (9 r ) k k (cid:1) / (2 rn ) < k Y r =1 (cid:0) (9 k ) k k (cid:1) / (2 rn ) < k Y r =1 (cid:0) (9 k ) k (cid:1) / (2 rn ) = (9 k ) k P kr =1 1 r < (9 k ) k ) k = exp (cid:18) k ) k ln(9 k ) (cid:19) < · k ) k ln(9 k ) = 1 + o (1) . (5)Putting together Equations (3), (4), and (5), we obtain:13Sud( n )) /n < ne (1 + o (1)) , as desired. Acknowledgements
Part of the research of the second author was done while he was visiting professor Delaram Kahrobaee atthe Graduate Center of City University of New York. He thanks for the hospitality during his visit.
References [1] R. A. Bailey, Peter J. Cameron, and Robert Connelly. Sudoku, Gerechte designs, resolutions, affinespace, spreads, reguli, and Hamming codes.
Amer. Math. Monthly , 115(5):383–404, 2008.[2] J. A. Bondy and U. S. R. Murty.
Graph theory , volume 244 of
Graduate Texts in Mathematics . Springer,New York, 2008.[3] Joshua Cooper and Anna Kirkpatrick. Critical sets for Sudoku and general graph colorings.
DiscreteMath. , 315:112–119, 2014.[4] Bertram Felgenhauer and Frazer Jarvis. Mathematics of Sudoku I.
Mathematical Spectrum , 39:15 , 22,2006.[5] William Feller.
An introduction to probability theory and its applications. Vol. I . Third edition. JohnWiley & Sons, Inc., New York-London-Sydney, 1968.[6] Marshall Hall. An existence theorem for Latin squares.
Bull. Amer. Math. Soc. , 51:387–388, 1945.[7] Antal Iv´anyi and Zsolt N´emeth. List coloring of Latin and Sudoku graphs. In , pages 23–34. NOVADAT Ltd., Gy˝or, 2011.[8] Izabela Kanaana and Bala Ravikumar. Row-filled completion problem for Sudoku.
Util. Math. , 81:65–84,2010.[9] Hung-Hsuan Lin and I-Chen Wu. Solving the minimum Sudoku problem.
Technologies and Applicationsof Artificial Intelligence (TAAI), 2010 International Conference on , 315:456–461, 2010.[10] Gary McGuire, Bastin Tugemann, and Gilles Civario. There is no 16-clue Sudoku: Solving the Sudokuminimum number of clues problem.
CoRR , abs/1201.0749, 2012.[11] Ryan M. Pedersen and Timothy L. Vis. Sets of mutually orthogonal Sudoku Latin squares.
CollegeMath. J. , 40(3):174–180, 2009.[12] Yato Takayuki and Seta Takahiro. Complexity and completeness of finding another solution and its ap-plication to puzzles.
IEICE transactions on fundamentals of electronics, communications and computersciences , 86(5):1052–1060, 2003.[13] J. H. van Lint and R. M. Wilson.