The n-queens completion problem

An n-queens configuration is a placement of n mutually non-attacking queens on an \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$n\times n$$\end{document}n×n chessboard. The n-queens completion problem, introduced by Nauck in 1850, is to decide whether a given partial configuration can be completed to an n-queens configuration. In this paper, we study an extremal aspect of this question, namely: how small must a partial configuration be so that a completion is always possible? We show that any placement of at most n/60 mutually non-attacking queens can be completed. We also provide partial configurations of roughly n/4 queens that cannot be completed and formulate a number of interesting problems. Our proofs connect the queens problem to rainbow matchings in bipartite graphs and use probabilistic arguments together with linear programming duality.


Introduction
An n-queens configuration is a set of n queens on an n × n chessboard such that no two are contained in the same row, column, or diagonal. The n-queens problem is to determine Q(n), the number of distinct n-queens configurations. The 8-queens problem was first published by German chess composer Max Bezzel in 1848, and attracted the attention of many mathematicians, including Gauss. We refer to the surveys [5,31] for a more detailed account of the history and many related problems. Recently, there has been some exciting progress [6,19,20,32] toward the n-queens problem and its toroidal version which was introduced by Pólya in 1918.
In this paper, we study a very natural variant, namely the n-queens completion problem, the first instance of which was introduced by Nauck [27] in 1850 (see Fig. 1).
In order to formulate the problem precisely, let us represent the chessboard by the 2-dimensional grid [  Hence, D + 0 and D − 0 are the two main diagonals of size n. We let D n = {D + k , D − k : k ∈ {−(n − 1), . . . , n − 1}} denote the set of all diagonals (see Fig. 2). Finally, we refer to the elements of L n = R n ∪ C n ∪ D n simply as lines. If n is clear from the context, we omit the subscripts.
A partial n-queens configuration is a subset Q ⊂ [n]×[n] such that every line contains at most one element of Q , and an n-queens configuration is a partial n-queens configuration of size n. We say that a partial n-queens configuration Q can be completed if there exists an n-queens configuration Q with Q ⊂ Q. Now, the n-queens completion problem is the following: Given a positive integer n and a partial n-queens configuration Q , can Q be completed?
When Q is empty, the question simply becomes whether an n-queens configuration exists. This is known to be the case whenever n / ∈ {2, 3}. However, the standard constructions (see [5]) are mostly obtained via some algebraic equations and are thus very rigid. In particular, by placing a few queens, one can quickly rule out such a construction. In Fig. 2 Representing the chessboard as a bipartite graph. In the complete bipartite graph K n,n , every edge represents a square of the chessboard. Every edge is "coloured" with a set of size 2 consisting of the two diagonals which contain the corresponding square contrast, the recent works [6,20,32] on counting n-queens configurations rely on probabilistic methods. Roughly speaking, the idea is to place queens iteratively using a random procedure, where in each step one of the still available squares is chosen at random, until (1 − o(1))n queens are placed. Then the absorbing method is used to show that with high probability such a partial configuration can be completed. By carefully analyzing this 2phased procedure, one can obtain lower bounds on Q(n). On a high level, this suggests that if a given partial n-queens configuration Q "looks random," it should be completable. We consider an extremal aspect of the n-queens completion problem, namely, how small must Q be so that a completion is always possible? This type of question has a long history and has been extensively studied for many related problems. For instance, Evans [12] conjectured in 1960 that any partial Latin square of order n with fewer than n cells filled can be completed, which would be best possible. Evan's conjecture was eventually proved by Smetaniuk [33] and independently by Andersen and Hilton [4] (see also [2] for a nice exposition about this problem). In a similar spirit, given a partial Steiner triple system of order n ≡ 1, 3 mod 6, a famous conjecture of Nash-Williams [26] would imply that if at most n/4 pairs are covered at every point, then the triple system can be completed. Motivated by this, we make the following definition. Definition 1.1 Define qc(n) as the maximum integer with the property that any partial n-queens configuration of size at most qc(n) can be completed. We call qc(n) the n-queens completion threshold.
We remark that this parameter also has an important algorithmic consequence. The n-queens problem has been used in many AI papers as a benchmark problem. Gent, Jefferson and Nightingale [14] showed that the n-queens completion problem is NPcomplete in general. However, observe that for all Q whose size is restricted to at most qc(n), the decision problem whether Q can be completed is trivial. We refer to [14] for a more thorough discussion of complexity and its ramifications for Artificial Intelligence research.
Our main result is that the completion threshold is linear in n.
To prove this theorem, in Sect. 2, we establish a connection between the n-queens completion problem and rainbow matchings in bipartite graphs. Then we deduce our lower bound modulo the proof of a "rainbow matching lemma." The study of rainbow subgraph problems has been very fertile in recent years (see e.g., [1,3,[8][9][10]13,15,17,18,[22][23][24][25]30]). Our new rainbow matching lemma (Lemma 2.2) relates to this large body of recent results in Extremal Combinatorics. Its proof, provided in Sect. 3, extends ideas of several earlier works. Besides proving the tool we need, our aim in this section is to discuss these important ideas and show how to use them to give a streamlined and mostly selfcontained argument. The upper bound in Theorem 1.2 is obtained in Sect. 4 via an explicit construction. The proof that our constructed partial configuration is not completable uses linear programming duality. We have not attempted to optimize the constants in either bound. Some of our arguments can certainly be improved to yield better bounds. However, new ideas are needed to determine qc(n) asymptotically. We discuss this and some other possible avenues for future research in the final Sect. 5.

Queens completion problem and rainbow matchings
In this section, we establish our lower bound on qc(n), by proving that any partial n-queens configuration of size at most n/60 can be completed.
One of the main ideas is to formulate the problem as a rainbow matching problem. This allows us to make use of a rich pool of tools and methods which have been developed for similar questions. A lot of research in this direction has been motivated by the famous Ryser-Brualdi-Stein conjecture. Originally formulated as a question about transversals in Latin squares, it postulates that every optimal edge colouring of K n,n contains a matching of size n − 1 which is rainbow, that is, all edges in it have distinct colours. The conjecture is still wide open. The best known bound, guaranteeing a rainbow matching of size n − O(log n/ log log n), was recently obtained by Keevash, Pokrovskiy, Sudakov and Yepremyan [17] and improved several earlier results.
The n-queens problem can be formulated in a very similar way. Given the n × n chessboard, consider the complete bipartite graph with one part R consisting of the n rows and one part C consisting of the n columns. Clearly, the edges of this graph correspond one-to-one to the squares of the chessboard. Moreover, a matching in the graph can be viewed as a placement of queens with no two queens in the same row or column. In order to encode the diagonal conflicts, we assign to each edge , that is, the two diagonals which contain the square (i, j). Hence, in analogy with the Ryser-Brualdi-Stein conjecture, we might view the diagonals as colours, but instead of having just one colour per edge, each edge receives a set of two colours (see Fig. 2).
Observe that an n-queens configuration corresponds exactly to a perfect matching which is rainbow, meaning now that the colour sets of the edges in the matching are pairwise disjoint. Moreover, given a partial n-queens configuration Q , let R be the set of remaining rows and C the set of remaining columns, and let G be the bipartite graph with parts R , C where (R i , C j ) ∈ R × C is still an edge if (i, j) is not diagonally attacked by any queen from Q . Then a completion of Q corresponds to a perfect rainbow matching of G. Note that assuming Q is not too large, G will still be relatively dense. Indeed, say we consider R i ∈ R , then the degree of R i in G will be at least n − 3|Q | since every queen in Q attacks at most 3 squares from R i (one in the same column and up to two diagonally).
Motivated by this, we want to understand under what conditions a dense graph G with a certain edge colouring has a perfect rainbow matching. For simplicity, let us first consider again the case when G is the complete bipartite graph K n,n . Notice that the Ryser-Brualdi-Stein conjecture only asks for a rainbow matching of size n − 1. In fact, when n is even, there are examples of optimal edge colourings of K n,n without a perfect rainbow matching. A fair amount of research has been devoted to find additional conditions which guarantee a perfect rainbow matching. One natural additional assumption is to restrict the degrees of the colours, where by degree of a colour we mean the number of edges with that colour. For instance, Erdős and Spencer [11] showed, by developing the lopsided Lovász local lemma, that if K n,n is properly edge-coloured and all colour degrees are at most n/16, then a perfect rainbow matching exists. Recently, Montgomery et al. [22] and independently Kim et al. [18] significantly strengthened this by proving that it suffices that all colour degrees are at most (1 − o(1))n. Theorem 2.1 ([18,22]) For every α > 0, if n is sufficiently large, every properly edge coloured K n,n with all colour degrees at most (1 − α)n has a perfect rainbow matching.
We will prove here a "rainbow matching lemma" which is of the same nature as Theorem 2.1 and suited to our needs. In order to state it, we need to introduce a bit more notation. Given a graph G, a t-fold edge colouring is an assignment of sets of size t to the edges of G. The colouring is called proper if the edges at a given vertex have pairwise disjoint colour sets, and a subgraph of G is called rainbow if all its edges have pairwise disjoint colour sets. In our application, we will only need 2-fold edge colourings (a square of the chessboard coloured with the two diagonals containing it). The degree of a colour c is the number of edges whose colour set contains c. Finally, we call the colouring linear if for every pair of colours there is at most one edge that contains both.
As discussed above, it is important for us to find perfect rainbow matchings in graphs which are not necessarily complete bipartite. The crucial conditions (which are trivially satisfied by K n,n ) are that the given graph is "approximately regular," meaning that all vertex degrees are roughly the same, and "uniformly dense" in the sense that between any sufficiently large sets there are many edges. Lemma 2.2 (rainbow matching lemma) For any α > 0 and t ∈ N, there exist > 0 and n 0 such that the following is true for any n ≥ n 0 . Let G be a bipartite graph with parts A, B of size n with a proper linear t-fold edge colouring. Assume that the following conditions are satisfied for some d: Then G has a perfect rainbow matching.
Let us briefly compare this result to earlier works. Conceptionally, the main difference is that we consider t-fold edge colourings instead of just normal edge colourings. A more subtle variation concerns condition (iii). Previous proofs required here that even sets of relatively small size, say, n, have many edges between them. In contrast, note that the size condition in (iii) is asymptotically optimal. For instance, when G is the disjoint union of two copies of K d,d+1 , where n = 2d + 1, then any sets A , B of size (1 + α)d have quadratically many edges between them, but there is no perfect matching. Finally, we remark that the assumption of the colouring being proper and linear can be weakened. Say the colouring is b-bounded if every colour appears on at most b edges incident to any given vertex, and any pair of colours appears on at most b edges together. Then our proof of Lemma 2.2 generalizes to the setting when the given colouring is b-bounded for some fixed constant b.
We will prove Lemma 2.2 in Sect. 3. In the remainder of this section, we use it to prove the lower bound of Theorem 1.2. In order to motivate the first step of our argument, observe that Lemma 2.2 is not directly applicable to our problem even if Q is empty and hence G is the complete bipartite graph K n,n . Although conditions (i) and (iii) trivially hold with d = n, condition (ii) is not satisfied because the main diagonals have size n as well. However, on average the colours (diagonals) have degree ∼ n/2. Our first goal is Fig. 3 The weight function for n = 3. All rows and columns have weight 5/2 = 5n/6, while all diagonals have weight at most 2 = 2n/3. For larger n, one can simply scale this weighting and achieve the same effect thus to find a subgraph G where not only the average degree of the colours is significantly smaller than the vertex degrees, but really all the colours have small degree. Equivalently, we want to find a subset ⊂ [n] × [n] of the chessboard such that the diagonals contain significantly fewer elements from than the rows and columns. It is beneficial to consider the following fractional variant of this problem, where the aim is to find a non-negative weight function on [n] × [n] such that the total weight of each diagonal is smaller than that of the rows and columns. One can easily find such a weight function for n = 3, say, and then scale it appropriately (see Fig. 3). otherwise.
Note that we scale i, j by n + 1 for symmetry reasons. With this definition, we have (For a line L, we use w(L) to denote the sum of the weights of all elements of L.) By symmetry of w, it suffices to consider D − k for fixed k ∈ {0, . . . , n − 1}. By the definition of w, the weight of any such diagonal with k ≥ n/3 is dominated by the one with k = n/3 , since for larger k, the size of the diagonals and the weights of the elements are non-increasing as k increases. Finally, for k ≤ n/3 , we have proving the claim.
Having found such a weighting, the existence of the desired set follows readily from a probabilistic argument. Simply choose by including every square (i, j) independently with probability w((i, j)). Then the expected degree of a line is simply its total weight under w, and with high probability all the actual degrees will be close to their expectation. (Throughout, we say that an event holds with high probability if its probability tends to 1 when n → ∞.) Note that after this initial step, we could apply Lemma 2.2 to find an n-queens configuration. However, if a partial configuration Q is given, then the graph G in which we seek a perfect rainbow matching might not be regular anymore, since a queen in Q might attack 3 elements from some row but only 1 element from another. Hence, in a second step, we want to regularize the degrees of G. We approach this problem again by considering the fractional variant first, and then using the same probabilistic argument as above to turn an appropriate weight function into a subgraph which approximates the weights. In fact, it is more convenient to only apply the probabilistic argument once, after both of the above steps have been carried out in the fractional setting. Proof We obtain the desired weighting iteratively. Starting with w 0 , in each step, given the current weighting w i , we perform a shift of the following form. Suppose u, v are two vertices in the same part, such that w i (u) >d and } and let X be the set of common neighbors of u and v. Now, we make the following adjustment to obtain a new weighting w i+1 . For all x ∈ X, we set w i+1 (ux) = w i (ux) − η |X| and w i+1 (vx) = w i (vx) + η |X| , and w i+1 (e) = w i (e) for all other edges. Hence, the total weight of u decreases by η, whereas the total weight of v increases by η, and the total weight of all other vertices remains unchanged. In particular, when performing such a shift, the total weight of all vertices in A remains the same, namelydn, and similarly for B. Hence, as long as there is some vertex whose weight is not equal tod, we can find another vertex in the same part and perform a shift like above. Observe also that the number of vertices whose total weight is not equal tod is reduced in each step, hence the procedure will eventually stop with a weighting w where all vertices have total weight exactlyd.
Consider an arbitrary edge e = ab. We need to check that during the procedure we did not change the weight of e by more than 2d /c. For this, observe that the total weight of both a and b is changed by at most d , and in each adjustment, we spread the adjustment over at least c common neighbors. Hence, the total change received by any given edge is at most 2d /c.
In the probabilistic argument, we will use the following standard concentration inequality.
Lemma 2.5 (Chernoff-Hoeffding bound) Let X be the sum of n independent Bernoulli random variables. Then for any λ ≥ 0, we have Proof of Theorem 1.2, lower bound We consider the complete bipartite graph with one part R consisting of the n rows and one part C consisting of the n columns. Moreover, we define a 2-fold edge colouring by assigning to each edge , that is, the two diagonals which contain the square (i, j). Crucially, observe that this colouring is proper and linear, because any two lines of the chessboard intersect in at most one square. Now, let Q ⊂ [n] × [n] be an arbitrary partial n-queens configuration of size βn, where β ≤ 1/60. Let R ⊂ R be the set of rows not containing a queen from Q , and let C ⊂ C be the set of columns not containing a queen from Q . Let G be the subgraph induced by R and C , after deleting all edges (R i , C j ) for which Q contains a queen on either diagonal We want to prove that Q can be completed, which is equivalent to showing that G has a perfect rainbow matching. Our aim is to apply the rainbow matching lemma. However, G itself is not suitable for such an application, because it might be quite irregular and the degrees of some colours could be significantly larger than those of the vertices. Hence, we find a suitable spanning subgraph G ⊂ G which meets the required conditions. Note that a perfect rainbow matching of G is also a perfect rainbow matching of G. In order to prepare for an application of Lemma 2.2, let α, > 0 be sufficiently small and n sufficiently large so that the lemma is applicable with t = 2.
By Proposition 2.3, there exists a weighting w 0 : . . , n − 1}. Now, we restrict this weighting to the edges of the graph G. Slightly abusing notation, we denote this restricted weighting again with w 0 . Hence, for all R i ∈ R and C j ∈ C , we still have w 0 (R i ), w 0 (C j ) ≥ 5n/6 + O(1) − 3βn since every queen in Q attacks at most 3 squares from R i , C j . For the same reason, any two vertices of G in the same part have at least n − 6βn common neighbors. We still have w 0 (D ± k ) ≤ 2n/3 + O(1) for all k ∈ {−(n − 1), . . . , n− 1}. Hence, for β ≤ 1/60, the weight of the diagonals (colours) is significantly lower than that of the rows and columns (vertices).
Next, we want to use this gap to regularize the weights of the vertices, while still maintaining a slight gap between the degrees of vertices and colours. Definē as the average weight of a vertex. We have 5n 6β)n, we can find a weighting w : E(G) → R such that every vertex has total weightd, and the weight of w 0 is changed by at most Now, we randomly sparsify the graph G to obtain a subgraph G which is approximately regular. For each edge e ∈ E(G), we define This way, we have p e ≤ 1 and p e ≥ 1/10, say. Let us include every edge e ∈ E(G) independently in G with probability p e . We want to show that with high probability G has the properties (i)-(iii) which we need to apply the rainbow matching lemma.
Let us consider any vertex u. The expected degree of u in G is d :=d/(1 + μ). The Chernoff bound (Lemma 2.5) implies that Hence, by a union bound over the at most 2n vertices, we see that (i) holds with high probability. Now, consider any colour c. Since the weight of each edge has increased by at most μ and c appears on at most n edges, the expected degree of c in G is at most (2n/3 + O(1) + μn)/(1 + μ). Thus, again using Chernoff's bound, we see that with high probability, all colour degrees are at most as needed for (ii). To see that the above inequality is correct, note that 2/3 + μ < 5/6 − 3β by the upper bound on β, with room to spare, so for small enough α, (1)).
A union bound over the at most 4 n choices for R , C thus shows that with high probability any two such sets have at least n 2 /100 edges between them, satisfying (iii).
Hence, by the probabilistic method, there exists a subgraph G which has all of the above properties. Finally, we can apply Lemma 2.2 to conclude that G has a perfect rainbow matching, which corresponds to a completion of Q .

Proof of the rainbow matching lemma
In this section, we prove Lemma 2.2. As discussed in Sect. 2, this lemma is inspired by Theorem 2.1. There are two main steps in its proof. In the first step, we find an approximate rainbow matching, that is, a rainbow matching which covers all but o(n) vertices. In the second step, we use local switchings to turn this approximate rainbow matching into a perfect rainbow matching. As a by-product, we also obtain a streamlined proof of Theorem 2.1.
The first step is achieved using the celebrated Rödl nibble. In order to formalize this, we need to introduce hypergraphs. Many other combinatorial questions can be formulated as matching problems in hypergraphs, which is why general results concerning matchings in hypergraphs are of great interest. For the following discussion, let H be a k-uniform linear hypergraph, where k is a fixed constant. A celebrated result of Pippenger (see [29]) based on the Rödl nibble says that if H is D-regular, for sufficiently large D, then it has an almost perfect matching.
(The same conclusion holds if H is not necessarily linear, but all codegrees are o(D). For simplicity, we will only consider linear hypergraphs here.) Notice that the "chessboard hypergraph" above is not regular. While all rows and columns (and the two main diagonals) have degree n, the other diagonals have smaller degree. What we will need here is a variant of Pippenger's theorem which does not require the hypergraph to be regular, as long as all the vertices we insist to cover have roughly the same degree, and the degrees of all other vertices are smaller (see Theorem 3.2). We remark that this observation is by no means novel, but it seems to be less known than the regular case, which is why we include its short derivation from the following classical result. Pippenger and Spencer originally formulated this result in the regular setting. However, since every linear k-uniform hypergraph can be embedded into a regular linear k-uniform hypergraph with the same maximum degree, the above version readily follows. Much stronger results have been proved subsequently [16,21].
From this, we can quite easily deduce the variant of Pippenger's theorem which we need.
Hence, there is i ∈ [t] for which X i ≥ (1 − 2δ)|U |, which gives us the desired matching.
Using Theorem 3.2, we can deduce the following result which gives us an almost-perfect rainbow matching. It remains to prove that this almost-perfect matching can be turned into a perfect rainbow matching. The crucial assumption to achieve this is that the degrees of the colours are significantly smaller than those of the vertices. This means that we can "reserve" some colours which will not be used for the almost-perfect matching, and then in the second step we can use these reserved colours to increase the size of the matching.
We next prove the tool which allows us to "split" the colours, that is, to set aside a set of colours for the final step. This is based on an important observation of Alon et al. [3]. They showed that, given a properly edge coloured K n , if one chooses every colour class independently with probability p, then the obtained subgraph has the property that between any two large enough sets A, B there are at least (1 − o(1))p|A||B| edges. Building on their ideas, but using a slightly different analysis, we prove the following general tool, which also provides upper bounds on the number of chosen edges.

Lemma 3.4 Let G be an n-vertex graph with a proper t-fold edge colouring. Choose every colour independently with probability p, and let G be the (random) subgraph consisting of all the edges e such that all the colours in the colour set of e have been chosen. Then with high probability, for any m and any disjoint sets A, B ⊂ V (G) of size at least m, we have that
Proof For two disjoint sets A , B ⊂ V (G), we define Z A ,B as the number of pairs of distinct edges e, e ∈ E (G[A , B ]) whose colour sets are not disjoint.
We claim that with high probability, for any disjoint sets A , B ⊂ V (G), we have that Thus, we see that the probability that (3.1) is not satisfied is at most 2n −8(a+b) . Since the number of choices for A and B with |A | = a and |B | = b is at most n a+b , a union bound (also over the n 2 choices for a and b) implies the claim. It now suffices to show that (3.1) implies the conclusion of the lemma. To this end, consider arbitrary disjoint sets A, B ⊂ V (G) of size at least m ≥ 1. Set r = |A| 3/5 and s = |B| 3/5 . We claim that there exist a partition of A into sets A 1 , . . . , A r and a partition  of B into sets B 1 , . . . , B s Indeed, for each vertex in A and B, respectively, put it in one of the sets A i and B i uniformly at random, all independently. Then where the sum is over all colours c and E c denotes the set of edges in G[A, B] whose colour set contains c. Here, we have used the assumption that the colouring is proper, which means that pairs of edges with overlapping colour sets do not share a vertex. In particular, for any colour c, we have |E c | ≤ min(|A|, |B|) ≤ √ |A||B| ≤ m −1/5 rs.
We can conclude that the desired partitions exist. Finally, invoking (3.1), we have where the last inequality holds by (3.2) and since 5 by definition of r, s).
With the tools above at hand, we can now prove the rainbow matching lemma.
Proof of Lemma 2. 2 We will assume that > 0 is sufficiently small and n is sufficiently large. Note that condition (iii) implies that e(G) ≥ αn 2 and hence d ≥ αn/2.
Set p 0 := 1 − α/t and p i = α/5t for i ∈ [5]. We first split the colours randomly as follows: for each colour independently, choose a label i ∈ {0, 1, 2, 3, 4, 5} at random by choosing i with probability p i . Let G i be the random subgraph of G consisting of all edges whose colour set has been completely labelled with i.
We first record some important properties of these subgraphs. With high probability, for every vertex u and each label i, we have This is because d G i (u) is the sum of d G (u) ≤ n independent Bernoulli variables and its expectation is p t i d G (u), so the Chernoff bound (Lemma 2.5) implies that By the probabilistic method, there exist graphs G 0 , . . . , G 5 which have all of the above properties. We will find in G 0 an almost perfect rainbow matching, and then use G 1 , . . . , G 5 to turn this into a perfect rainbow matching. For the second step, we will need the following "expansion" property of the graphs G i . (This is the property which allows us to have the asymptotically optimal size condition in (iii).) To see this, let T − be the set of vertices which have fewer than αp t i d|S|/10n neighbors in S, and let T + be the set of vertices which have more than (1 + )p t i |S| neighbors in S. By (3.3), there are at least (1 − 2 )p t i d|S| edges going out of S. By definition of T − , at most n · αp t i d|S|/10n of these edges go to a vertex in T − . Moreover, we have |T + | ≤ n, as otherwise we can use (3.4

) in bounding
to reach a contradiction. Hence, at least (1−α/5)p t i d|S| of the edges leaving S go to vertices which are neither in T − nor in T + . Since each vertex not in T + has at most (1 + )p t i |S| neighbors in S, there must be at least vertices where these edges go to. Each of these vertices is not in T − and hence has at least αp t i d|S|/10n ≥ 1/3 |S| neighbors in S.
Now, we begin with the construction of the matching. In the first step, we find an almost-perfect rainbow matching in G 0 . By (3.3), we know that every vertex has degree (1 ± 2 )p t 0 d in G 0 . By condition (ii), all colours have degree at most (1 − α)d. Since we can apply Corollary 3.3 to find a rainbow matching M 0 of size at least (1 − 8 )n. Now, we want to turn M 0 into a perfect rainbow matching. We will achieve this iteratively by increasing the size of the matching in each step by one. More precisely, we show that for all ∈ {0, . . . , n − |M 0 |}, there exists a rainbow matching M of size |M 0 | + in G which contains at most 5 edges outside G 0 . Clearly, this is true for = 0, and ultimately M n−|M 0 | will be a perfect rainbow matching in G as desired. Thus, it suffices to show that given M as above for some < n − |M 0 |, we can find M +1 .
We accomplish this by finding a short augmenting path. Call a sequence v 1 , v 2 , . . . , v 2k of vertices augmenting if the following holds: • v 1 and v 2k are distinct and not covered by M ; are pairwise colour-disjoint and also colourdisjoint from all edges in M .
Observe that if we have such a sequence, we can increase the size of our rainbow matching by one. For this, it is first helpful to notice that, by taking a shortest such sequence, we can assume that the vertices v 1 , v 2 , . . . , v 2k are distinct. Indeed, if v j = v j , then as G is bipartite, j and j have the same parity and hence the sequence could be shortened while preserving the augmenting property. When v 1 , v 2 , . . . , v 2k are distinct, then it is clear that } yields a rainbow matching of size |M | + 1.
We will now find an augmenting sequence of length 10, thus ensuring that at most 5 edges from outside G 0 are added to the matching. The 5 augmenting edges will come from different G i 's and will thus be pairwise colour-disjoint. We also have to guarantee that they do not have a colour which is already used. Therefore, call a colour blocked if it is contained in the colour set of some edge in M . Since the inductive hypothesis gives us that M contains at most 5 edges outside G 0 , at most 5t colours with a non-zero label are blocked. Call an edge blocked if its colour set contains a blocked colour. Since the colouring is proper, for every vertex u and each i ∈ [5], at most 5t ≤ 5t · 8 n ≤ √ n edges of G i at u are blocked. This means that the graphs G i , after removing blocked edges, still have the properties (3.3), (3.4) and ( †), up to slightly changing the parameters.
Let a ∈ A and b ∈ B be two arbitrary vertices which are not covered by M . Define B 1 as the set of all b 1 ∈ N G 1 (a) such that ab 1 is not blocked and b 1 is covered by M . Note that we have Further, let A 2 be the set of vertices which are matched to the vertices in B 1 by M . Next, let B 3 be the set of all vertices b 3 for which there exists a 2 ∈ A 2 such that a 2 b 3 ∈ E(G 3 ) is not blocked and b 3 is covered by M . We claim that |B 3 | ≥ (1 − α)d. Indeed, since |A 2 | = |B 1 | ≥ n, by ( †), there exists a set B 3 of size at least (1 − α/2)d such that every b 3 ∈ B 3 has at least 1/3 |A 2 | neighbors in A 2 . For each such vertex b 3 , at most √ n edges of G 3 are blocked, and hence there exists some a 2 ∈ A 2 such that a 2 b 3 ∈ E(G 3 ) is not blocked. By removing at most 8 n vertices from B 3 which are not covered by M , we find the set B 3 with the required properties.
Finally, let A 4 be the set of vertices which are matched to the vertices in B 3 by M . With exactly the same argument, starting from b, we find sets A 1 , B 2 , A 3 , B 4 with the analogous properties, where G 1 is replaced by G 2 and G 3 is replaced by G 4 .  4). Since in total there are at most √ n 2 blocked edges, we can find an edge a 4 b 4 ∈ E(G 5 ) between A 4 and B 4 which is not blocked. Let b 3 ∈ B 3 be the match of a 4 . By definition of B 3 , there exists a 2 ∈ A 2 such that a 2 b 3 ∈ E(G 3 ) is not blocked. Finally, let b 1 be the match of a 2 and note that by definition of B 1 , we have that ab 1 ∈ E(G 1 ) is not blocked. Similarly, starting from b 4 , find vertices a 3 , b 2 , and a 1 . Then a, b 1 , a 2 , b 3 , a 4 , b 4 , a 3 , b 2 , a 1 , b is an augmenting sequence as desired (cf. Fig. 4).

Upper bound
In this section, we establish our upper bound on qc(n), by constructing partial n-queens configurations which cannot be completed. Before proving the upper bound given in Theorem 1.2, we give the following very simple argument which shows that qc(n) ≤ n/3 + O(1). Assume for simplicity that n is divisible by 3. Partition the chessboard into 9 squares of side length n/3. Now, simply view the central box as an n/3 × n/3 chessboard, and put an n/3-queens configuration there. (This is possible whenever n/3 ≥ 4.) Clearly, this is a partial n-queens configuration of the original chessboard. We claim that it cannot be completed. Indeed, no additional queen can be placed in any of the 4 boxes which share a side with the central box. Hence, if it was possible to place 2n/3 additional queens, then they all have to be placed into the 4 corner boxes. Hence, we can assume that at least n/3 queens are placed in two corner boxes which lie diagonally opposite to each other, say top left and right bottom. However, these two corner boxes together with the central box are covered by 2n/3 − 1 parallel diagonals. Since n/3 of these diagonals are already blocked by queens in the central box, it is impossible to place another n/3 queens into the two corner boxes. Now, we continue with the proof of our improved bound. While the construction is similar (we place an m-queens configuration into the middle of the chessboard), a more elaborate argument is needed to show that it cannot be completed. In fact, we formulate a very general setup based on linear programming duality which can also be used to improve our bound.
Given the n × n chessboard, a line weighting is a function w : L → [0, 1]. Its value is simply L∈L w(L). We say that w covers a square (i, j) if the sum of the weights of the lines containing that square is at least 1, that is, Proof Let w be a line weighting which covers . Suppose that Q can be completed to an n-queens configuration Q. Hence, Q \ Q ⊂ has size n − |Q |. For each (i, j) ∈ Q \ Q , we have L∈L : (i,j)∈L w(L) ≥ 1. By summing this inequality over all (i, j) ∈ Q \ Q , since any line will only appear at most once on the left-hand side, we see that the value of w is at least n − |Q |, which yields a contradiction.
We will use Proposition 4.1 to prove that our constructed partial n-queens configuration cannot be completed. For this, we need to find a suitable line weighting which certifies this. As mentioned before, in our construction, Q will be an m-queens configuration in the centre of the chessboard. This restricts to the four corner boxes of side length (n − m)/2. We will first define a line weightingŵ which covers all elements of these four corner boxes. Subsequently, we observe that we can actually set the weight of all diagonals which contain an element of Q to 0, thus significantly reducing the value of the line weighting. In the weightingŵ, the diagonals which are close to the main diagonals will have larger weight than those which are further away. Hence, the value of our line weighting is reduced the most if the elements of Q are "close" to the main diagonals. It turns out that a well-known construction of (toroidal) n-queens configurations (cf. [5]) has the property that many queens are close to the main diagonals. Proof For each i ∈ {1, . . . , (n − 1)/2}, we place a queen on (i, 2i). For each i ∈ {(n + 1)/2, . . . , n}, we place a queen on (i, 2i − n). The quantity of interest then becomes Proof of Theorem 1.2, upper bound Suppose n is large enough. Let us first assume that n is odd. Let m be the largest integer which is at most 0.241n and ≡ 1 mod 6. (We will actually prove that qc(n) < m ≤ 0.241n < n/4.) Set t = (n − m)/2. Let Q be the m-queens configuration from Proposition 4.2. We embed it in the centre of the chessboard, more precisely, we let Q = {(i + t, j + t) : (i, j) ∈ Q}. Obviously, Q is a partial n-queens configuration. We want to show that it cannot be completed. The black squares in the centre represent the partial configuration Q . The grey squares share a row or column with Q , leaving the four t × t corners. Each square there is covered by the weight of its row, column and the longer diagonal. Ultimately, we can "remove" the diagonals which pass through Q Let ⊂ [n] × [n] be the set of squares not attacked by Q . Clearly, is contained in the setˆ which consists of the four t × t corners of the chessboard. We will first define a line weighting which coversˆ . For this, defineŵ as follows: for each i ∈ {1, . . . , t}, set Moreover, for each k ∈ {−(t − 1), . . . , t − 1}, set Set the weight of all other lines to 0. We claim thatŵ coversˆ . By symmetry, it suffices to consider (i, j) ∈ [t] × [t]. We then have where the last inequality holds by the triangle inequality. This proves the claim.
Notice also thatŵ has value 3t + O(1), where the 2t rows and 2t columns contribute 1/4 + O(1/t) on average, and the 4t diagonals contribute 1/2 + O(1/t) on average. Now, observe that we can set the weight of all diagonals which contain some queen from Q to 0, because no element of such a diagonal is in . The obtained line weighting w then still covers , and its value is reduced (with respect to the value ofŵ) by By Proposition 4.2, we have Altogether, we conclude that the value of w is at most If this value is smaller than n − |Q | = 2t, then Proposition 4.1 certifies that Q cannot be completed. This condition informed our choice of m. It is straightforward to check that with m = 0.241n + O(1) and t = (n − m)/2 we indeed have the desired strict inequality. Finally, if n is even, we can simply repeat the above construction with n = n − 1, and add weight 1 to R n and C n to get the desired weighting.

Concluding remarks
In this paper, we studied the n-queens completion problem, showing that if at most n/60 queens are placed on an n × n chessboard, mutually non-attacking, then they can be completed to an n-queens configuration. We also provided a construction of a partial configuration of size roughly n/4 which cannot be completed. It would be very interesting to close the gap between the lower and upper bound. Problem 5.1 Determine the n-queens completion threshold qc(n) asymptotically.
In fact, note that our proof of the upper bound (via Proposition 4.1) shows that Q does not even have a fractional completion. In more detail, given a partial configuration Q , let as before be the set of squares which are not attacked by Q . We say that Q has a fractional completion if there exists a nonnegative weight function on with the total weight n − |Q | such that the weight along each line is at most 1. Similar to qc(n), one can define qc * (n) as the fractional n-queens completion threshold, that is, the largest integer with the property that any partial n-queens configuration on an n × n chessboard with at most qc * (n) queens has a fractional completion. Obviously, qc(n) ≤ qc * (n), and (by virtue of our proof) the upper bound in Theorem 1.2 also holds for qc * (n). We conjecture that in fact qc(n) and qc * (n) are asymptotically equal. This breaks Problem 5.1 into two natural sub-problems, both of which are interesting on their own. Show that qc(n) ∼ qc * (n) and determine qc * (n).
So far, we were mainly concerned with finding one completion of a given partial nqueens configuration Q (or showing that none exists). However, it is also natural to ask how many distinct completions there are. For instance, Nauck's original configuration ( Fig. 1) has 2 completions. A trivial upper bound is the number of all n-queens configurations, which is at most n! ≤ n n . One can adapt our proof to show that not only can any partial configuration of size at most n/60 be completed, but even that there are super-exponentially many completions.
Theorem 5.2 For large enough n, any partial n-queens configuration of size at most n/60 can be completed in at least n (n) different ways.
This follows immediately (by following the proof of Theorem 1.2) from a counting version of our rainbow matching lemma. Namely, in Lemma 2.2, under the same assumptions, there exist n (n) perfect rainbow matchings. The approach to prove this is quite standard by now and has been used for many counting problems in combinatorics (and also in [6,20,32] for counting n-queens configurations), so we omit the details. Roughly speaking, one requires a counting version of Theorem 3.2 which in the proof of Lemma 2.2 yields n (n) different approximate rainbow matchings M 0 . Then, by inspecting our proof, each of these approximate rainbow matchings can be augmented to a perfect rainbow matching, and at most n O( n) approximate matchings produce the same perfect matching, which gives the desired result.
We believe that the statement Theorem 5.2 remains true if n/60 is replaced by (1 − o(1))qc(n). Also, note that the counting result is quite rough. It would be interesting to determine the number of completions for a given partial configuration Q more accurately, say within subexponential factors. Perhaps some of the techniques introduced in [32] are adaptable to this "generalized n-queens problem." Finally, it might also be interesting to look at embeddings instead of completions. Generally speaking, if some partial instance of a combinatorial structure is not completable, one might still wonder if it can be embedded into a complete instance of larger order, and if so, by how much the order has to be increased for this to be possible. For instance, while there are partial Latin squares of order n with n cells filled in which cannot be completed (to a Latin square of order n), Evans [12] showed that any partial Latin square of order n can be embedded into a Latin square of order at most 2n. The corresponding result for Steiner triple systems was obtained by Bryant and Horsley [7], who thereby proved a conjecture of Lindner. For a general discussion of such problems in graph theory, see [28].
Given a partial n-queens configuration Q , we thus ask what is the smallest n * such that Q can be embedded into an n * -queens configuration Q. Here, by embedding we mean that the n × n chessboard on which Q is given is a subsquare of the larger board, that is, there exist i 0 , j 0 such that (i + i 0 , j + j 0 ) ∈ Q for all (i, j) ∈ Q . Note that n * = n if and only if Q is completable. The existence of n * was first shown in [14] (with an implicit upper bound linear in n), which also follows immediately from our Theorem 1.2.