# The n-queens completion problem

An n-queens configuration is a placement of n mutually non-attacking queens on an 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.

## Authors

• 1 publication
• 1 publication
• 2 publications
12/09/2015

### Partial Reinitialisation for Optimisers

Heuristic optimisers which search for an optimal configuration of variab...
09/16/2019

### Multitype Integer Monoid Optimization and Applications

Configuration integer programs (IP) have been key in the design of algor...
12/01/2020

### Difference-restriction algebras of partial functions with operators: discrete duality and completion

We exhibit an adjunction between a category of abstract algebras of part...
10/14/2021

### On the proper interval completion problem within some chordal subclasses

Given a property (graph class) Π, a graph G, and an integer k, the Π-com...
06/03/2019

### Betti numbers of unordered configuration spaces of small graphs

The purpose of this document is to provide data about known Betti number...
11/29/2017

### A maximizing characteristic for critical configurations of chip-firing games on digraphs

Aval et al. proved that starting from a critical configuration of a chip...
09/23/2020

### Cyclic Shift Problems on Graphs

We study a new reconfiguration problem inspired by classic mechanical pu...
##### This week in AI

Get the week's most popular data science and artificial intelligence research sent straight to your inbox every Saturday.

## 1 Introduction

An -queens configuration is a set of queens on an chessboard such that no two are contained in the same row, column, or diagonal. The -queens problem is to determine , the number of distinct -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] towards the -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 -queens completion problem, which was introduced by Nauck [27] in 1850 (see Figure 1).

In order to formulate the problem precisely, let us represent the chessboard by the -dimensional grid . For , define

 Ri={(i,j):j∈[n]}, Ci={(j,i):j∈[n]}.

We let denote the set of all rows and the set of all columns. For , define

 D+k ={(i,j)∈[n]×[n]:i+j−(n+1)=k}, D−k ={(i,j)∈[n]×[n]:i−j=k}.

Hence, and are the two main diagonals of size . We let denote the set of all diagonals (see Figure 2 below). Finally, we refer to the elements of simply as lines. If is clear from the context, we omit the subscripts.

A partial -queens configuration is a subset such that every line contains at most one element of , and an -queens configuration is a partial -queens configuration of size . We say that a partial -queens configuration can be completed if there exists an -queens configuration with . Now, the -queens completion problem is the following: Given an integer and a partial -queens configuration , can be completed?

Obviously, when is empty, then the question simply becomes whether an -queens configuration exists. This is known to be the case whenever . 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 contrast, the recent works on counting -queens configurations rely on probabilistic methods. Roughly speaking, the idea there is to place queens iteratively using a random procedure, where in each step one of the still available squares is chosen at random, until

queens are placed. Then the absorbing method is used to show that with high probability, such a partial configuration can be completed. By carefully analysing this 2-phase procedure, one can obtain lower bounds on

. On a high level, this suggests that if a given partial -queens configuration “looks random”, it should be completable.

We consider an extremal aspect of Nauck’s problem, namely, how small must 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 with less than cells filled in can be completed, which would be best possible. The 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 , a famous conjecture of Nash-Williams [26] would imply that if at most pairs are covered at every point, then it can be completed. Motivated by this, we make the following definition.

###### Definition 1.1.

Define as the maximum integer with the property that any partial -queens configuration of size at most can be completed. We call the -queens completion threshold.

We remark that this parameter also has an important algorithmic consequence. The -queens problem has been used in many AI papers as a benchmark problem. Gent, Jefferson and Nightingale [14] showed that the -queens completion problem is NP-complete in general. However, observe that for all whose size is restricted to at most , the decision problem whether 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 .

###### Theorem 1.2.

For all sufficiently large , we have

To prove this theorem, in Section 2, we will establish a connection between the -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 Section 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 self-contained argument. The upper bound in Theorem 1.2 will be obtained in Section 4 via an explicit construction. The proof that our constructed partial configuration is not completable will use 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 asymptotically. We will discuss this and some other possible avenues for future research in the final Section 5.

## 2 Queens completion problem and rainbow matchings

In this section, we establish our lower bound on , by proving that any partial -queens configuration of size at most can be completed.

One of the main ideas is to cast 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 contains a matching of size 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 , was recently obtained by Keevash, Pokrovskiy, Sudakov and Yepremyan [17] and improved several earlier results.

We will now see that the -queens problem can be formulated in a very similar way. Given the chessboard, consider the complete bipartite graph with one part consisting of the rows and one part consisting of the 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 in the same row or column. In order to encode the diagonal conflicts, we assign to each edge the set , that is, the two diagonals which contain the square . 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 Figure 2).

Observe that an -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 -queens configuration , let be the set of remaining rows and the set of remaining columns, and let be the bipartite graph with parts where is still an edge if is not attacked by any queen from . Then a completion of corresponds to a perfect rainbow matching of . Note that assuming is not too large, will still be relatively dense. Indeed, say if we consider , then the degree of in will be at least since every queen in attacks at most squares from .

Motivated by this, we want to understand under what conditions a dense graph with a certain edge colouring has a perfect rainbow matching. For simplicity, let us first consider again the case when is the complete bipartite graph . Notice that the Ryser–Brualdi–Stein conjecture only asks for a rainbow matching of size . In fact, when is even, there are examples of optimal edge colourings of 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 such 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 is properly edge-coloured and all colour degrees are at most , then a perfect rainbow matching exists. Recently, Montgomery, Pokrovskiy and Sudakov [22] and independently Kim, Kühn, Kupavskii and Osthus [18] significantly strengthened this by proving that it suffices if all colour degrees are at most .

###### Theorem 2.1 ([18, 22]).

For every , if is sufficiently large, every properly edge coloured with all colour degrees at most 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 , a -fold edge colouring is an assignment of sets of size to the edges of . The colouring is called proper if the edges at a given vertex have pairwise disjoint colour sets, and a subgraph of is called rainbow if all its edges have pairwise disjoint colour sets. In our application, we will only need -fold edge colourings (a square of the chessboard coloured with the two diagonals containing it). The degree of a colour is the number of edges whose colour set contains . Finally, we call the colouring linear if two distinct colours appear on at most one edge together.

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 ) 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 and there exist and such that the following is true for any . Let be a bipartite graph with parts of size  with a proper linear -fold edge colouring. Assume that the following conditions are satisfied for some :

1. [label=()]

2. every vertex has degree ;

3. every colour has degree at most ;

4. any two sets and of size at least have at least edges between them.

Then has a perfect rainbow matching.

Let us briefly compare this result to earlier works. Conceptionally, the main difference is that we consider -fold edge colourings instead of just normal edge colourings. A more subtle variation concerns condition 3. Previous proofs required here that even sets of relatively small size, say, , have many edges between them. In contrast, note that the size condition in 3 is asymptotically optimal. For instance, when is the disjoint union of two copies of , where , then any sets of size 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 -bounded if every colour appears on at most edges incident to any given vertex, and any pair of colours appears on at most edges together. Then our proof of Lemma 2.2 straightforwardly generalizes to the setting when the given colouring is -bounded for some fixed constant .

We will prove Lemma 2.2 in Section 3. In the remainder of this section, we will 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 is empty and hence is the complete bipartite graph . Although conditions 1 and 3 trivially hold with , condition 2 is not satisfied because the main diagonals have size as well. However, on average, the colours (diagonals) have degree . Our first goal is thus to find a subgraph 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 essentially want to find a subset of the chessboard such that the diagonals contain significantly less elements from than the rows and columns. It is beneficial to consider a fractional variant of this problem, where the aim would be to find a non-negative weight function on such that the total weight of the diagonals is smaller than that of the rows and columns. One can easily find such a weight function for , say, and then scale it appropriately (see Figure 3).

###### Proposition 2.3.

There exists a weighting with the property that every row and column has total weight , but every diagonal has weight at most .

Proof. Define a weight function by setting

 w((i,j)):=⎧⎨⎩1/2if i/(n+1),j/(n+1)∈[1/3,2/3],3/4if i/(n+1),j/(n+1)∈[0,1/3)∪(2/3,1],1otherwise.

Note that we scale by for symmetry reasons. With this, we have for all and for all . Moreover, we claim that for any . By symmetry of , it suffices to consider for fixed . Clearly, by the definition of , the weight of any such diagonal with is dominated by the one with , since for larger , the size of the diagonals and the weights of the elements are non-increasing as increases. Finally, for , we have

 w(D−k) =(n/3−k)⋅3/4+k⋅1+(n/3−k)⋅1/2+k⋅1+(n/3−k)⋅3/4+O(1) =2n/3+O(1),

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 independently with probability . Then the expected degree of a line is simply its total weight under , 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 when .) Note that after this initial step, we would be in a position to apply Lemma 2.2 to find an -queens configuration. However, if a partial configuration is given, then the graph in which we seek a perfect rainbow matching might not be regular anymore, since a queen in might attack elements from some row but only element from another. Hence, in a second step, we want to regularize the degrees of . 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.

###### Proposition 2.4.

Let be a bipartite graph with parts of size  where any two vertices in the same part have at least common neighbours. Let be an edge weighting such that for all vertices , where . Then there exists an edge weighting such that the total weight of edges at every vertex is , and for all .

Proof. We obtain the desired weighting successively. Starting with , in each step, given the current weighting , we perform a shift of the following form: Suppose are two vertices in the same part, such that and . Set and let be the set of common neighbours of and . Now, we make the following adjustment to obtain a new weighting . We set and for all , and for all other edges. Hence, the total weight of decreases by , whereas the total weight of 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 remains the same, namely , and similarly for . Hence, as long as there is some vertex whose weight is not equal to , 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 to is reduced in each step, hence the procedure will eventually stop with a weighting where all vertices have total weight exactly .

Consider an arbitrary edge . We need to check that during the procedure we did not change the weight of by more than . For this, observe that the total weight of both and is changed by at most , and in each adjustment, we spread the adjustment over at least common neighbours. Hence, the total change received by any given edge is at most .

In the probabilistic argument, we will use the following standard concentration inequality.

###### Lemma 2.5 (Chernoff bound).

Let be the sum of

independent Bernoulli random variables. Then for any

, we have

 P[|X−E[X]|≥λ]≤2exp(−2λ2/n).

Proof of Theorem 1.2, lower bound. We consider the complete bipartite graph with one part consisting of the rows and one part consisting of the columns. Moreover, we define a -fold edge colouring by assigning to each edge the set , that is, the two diagonals which contain the square . Crucially, observe that this colouring is proper and linear, because any two lines of the chessboard intersect in at most one square.

Now, let be an arbitrary partial -queens configuration of size , where . Let be the set of rows not containing a queen from , and let be the set of columns not containing a queen from . Let be the subgraph induced by and , after deleting all edges for which contains a queen on either diagonal .

We want to prove that can be completed, which is equivalent to showing that has a perfect rainbow matching. Our aim is to apply the rainbow matching lemma. However, 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, in the following, we will find a suitable spanning subgraph which meets the required conditions. Note that a perfect rainbow matching of is also a perfect rainbow matching of . In order to prepare for an application of Lemma 2.2, let be sufficiently small and sufficiently large so that the lemma is applicable with .

By Proposition 2.3, there exists a weighting such that and for all , and for all . Now, we restrict this weighting to the edges of the graph . Slightly abusing notation, we denote this restricted weighting again with . Hence, for all and , we then still have since every queen in attacks at most squares from . For the same reason, any two vertices of in the same part have at least common neighbours. Obviously, we still have for all . Hence, for , 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. Define

 ¯d:=1(1−β)n∑(Ri,Cj)∈E(G)w0((Ri,Cj)). (2.1)

as the average weight of a vertex. Clearly, we have , so by applying Proposition 2.4 with and , we can find a weighting such that every vertex has total weight , and the weight of is changed by at most

 μ:=2d′/c=6β/(1−6β)+o(1)≤1/9+o(1).

Now, we randomly sparsify the graph to obtain a subgraph which is approximately regular. For each edge , we define

 pe:=w(e)1+μ.

This way, we have and , say. Let us include every edge independently in with probability . We want to show that with high probability, has the properties 13 we need to apply the rainbow matching lemma.

Let us consider any vertex . The expected degree of in is . The Chernoff bound (Lemma 2.5) implies that

 P[|dG′(u)−d|≥ϵd]≤2exp(−2(ϵd)2/n)=exp(−Ω(n)).

Hence, by a union bound over the at most vertices, we see that 1 holds with high probability.

Now, consider any colour . Since the weight of each edge has increased by at most and appears on at most edges, the expected degree of in is at most . Thus, again using Chernoff’s bound, we see that with high probability, all colour degrees are at most

 2/3+μ+ϵ1+μn≤(1−α)¯d1+μ=(1−α)d,

as needed for 2. To see that the above inequality is correct, note that by the upper bound on , with room to spare, so for small enough we have .

Finally, consider two sets and of size at least . First observe that in , there are at least edges between and . This is because every queen in trivially attacks at most squares of the grid given by and . Since we have for all edges , we see that . By Chernoff’s bound,

 P[eG′(R′′,C′′)≤n2/100]≤2exp(−2(n2/100)2/n2)≤exp(−n3/2).

A union bound over the at most choices for thus shows that with high probability, any two such sets have at least edges between them, satisfying 3 generously.

Hence, by the probabilistic method, there exists a subgraph which has all of the above properties. Finally, we can apply Lemma 2.2 to conclude that has a perfect rainbow matching, which corresponds to a completion of .

## 3 Proof of the rainbow matching lemma

In this section, we prove Lemma 2.2. As discussed in Section 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 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. A -uniform hypergraph consists of a set of vertices and a set of edges , where every edge is a subset of of size . It is called linear if any two vertices are contained in at most one edge together. A matching is a set of disjoint edges. A vertex is covered by if it belongs to some edge in . The degree of a vertex is simply the number of edges containing it.

To see the connection with the -queens problem let us define the hypergraph whose vertices are the lines of the chessboard and every square is represented by the edge . Then the matchings of correspond exactly to partial -queens configurations.

Many other combinatorial questions can be formulated as matching problems in hypergraphs, which is why general results concerning the latter are of great interest. For the following discussion, let be a -uniform linear hypergraph, where is a fixed constant. A celebrated result of Pippenger (see [29]) based on the Rödl nibble says that if is -regular, for sufficiently large , then it has an almost perfect matching. (The same conclusion holds if is not necessarily linear, but all codegrees are . 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 , 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 the short derivation from the following classical result.

###### Theorem 3.1 (Pippenger–Spencer [29]).

For any and there exists such that the following holds for all . Let be a linear -uniform hypergraph with maximum degree . Then can be partitioned into at most matchings.

Pippenger and Spencer originally formulated this result in the regular setting. However, since every linear -uniform hypergraph can be embedded into a regular linear -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.

###### Theorem 3.2.

For any and there exists such that the following holds for all . Let be a linear -uniform hypergraph with maximum degree at most . Let be a set of vertices all having degree at least . Then there exists a matching in which covers all but of the vertices of .

Proof. By Theorem 3.1, there are matchings which partition such that . For every define which is the number of vertices in that are covered by . Then we have

 1tt∑i=1Xi=1t∑e∈E(H)|e∩U|=1t∑u∈UdH(u)≥(1−δ)D|U|(1+δ)D≥(1−2δ)|U|.

Hence, there is for which , which gives us the desired matching.

Using Theorem 3.2, we can deduce the following result which gives us an almost-perfect rainbow matching.

###### Corollary 3.3.

For any and there exists such that the following holds for all . Let be a graph with a proper linear -fold edge colouring. Assume that all vertices have degree and all colours have degree at most . Then there exists a rainbow matching which covers all but vertices.

Proof. Define the following hypergraph . The vertex set of is , where is the set of all colours. For every edge , we define the hyperedge , where is the colour set of . Hence, is -uniform.

First, observe that is linear. Indeed, for any distinct , if , then there is no hyperedge containing and , and if , then is the only hyperedge containing and . For and , there is at most one hyperedge containing and because the colouring is proper, and for distinct , there is at most one hyperedge containing and since the colouring is linear.

Next, the maximum degree of is at most by assumption, and all vertices in have degree at least . Apply Theorem 3.2 (with and ) to find a matching in which covers all but vertices of . Define . Clearly, is a matching in and covers all but vertices of . Moreover, for any two edges , their colour sets are disjoint since and are both in . Hence, is rainbow.

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. This is based on an important observation of Alon, Pokrovskiy and Sudakov [3]. They showed that, given a properly edge coloured , if one chooses every colour class independently with probability , then the obtained subgraph has the property that between any two large enough sets there are at least 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 be an -vertex graph with a proper -fold edge colouring. Choose every colour independently with probability , and let be the random subgraph consisting of all edges whose colour set has been chosen completely. Then with high probability, for any and any disjoint sets of size at least , we have that

 |eG′(A,B)−pteG(A,B)|≤9tm−1/5|A||B|√logn.

Proof. For two disjoint sets , we define as the number of pairs of distinct edges whose colour sets are not disjoint.

We claim that with high probability, for any disjoint sets , we have that

 |eG′(A′,B′)−pteG(A′,B′)|≤ZA′,B′+2√(|A′|+|B′|)|A′||B′|logn. (3.1)

Indeed, fix and set and . By deleting an edge from every pair of edges that have overlapping colour sets, we obtain a rainbow subgraph of with at least edges. Let be the random variable counting the number of these edges which are in . Since is a sum of at most independent Bernoulli variables, the Chernoff bound (Lemma 2.5) implies that

 P[|X−E[X]|≥λ]≤2exp(−2λ2/ab),

for any . Set . Since and , we have

 |eG′(A′,B′)−pteG(A′,B′)|≤|X−E[X]|+ZA′,B′.

Thus, we see that the probability that (3.1) is not satisfied is at most . Since the number of choices for and with and is at most , a union bound (also over the choices for and ) implies the claim.

It now suffices to show that (3.1) implies the conclusion of the lemma. To this end, consider arbitrary disjoint sets of size at least . Set and . We claim that there exist a partition of into sets and a partition of into sets such that

 r∑i=1s∑j=1ZAi,Bj≤tm−1/5eG(A,B)≤tm−1/5|A||B|. (3.2)

Indeed, for each vertex in and , respectively, put it in one of the sets and uniformly at random, all independently. Then

 E[r∑i=1s∑j=1ZAi,Bj]=1rsZA,B≤1rs∑c(|Ec|2)≤min(|A|,|B|)rs∑c|Ec|≤m−1/5teG(A,B),

where the sum is over all colours and denotes the set of edges in whose colour set contains . 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 , we have .

We can conclude that the desired partitions exist. Finally, invoking (3.1) and (3.2), we have

 |eG′(A,B)−pteG(A,B)| ≤r∑i=1s∑j=1∣∣eG′(Ai,Bj)−pteG(Ai,Bj)∣∣ ≤r∑i=1s∑j=1ZAi,Bj+2√lognr∑i=1s∑j=1√(|Ai|+|Bj|)|Ai||Bj| ≤9tm−1/5|A||B|√logn,

where the last inequality holds since

 r∑i=1s∑j=1√(|Ai|+|Bj|)|Ai||Bj| ≤r∑i=1√|Ai|s∑j=1|Bj|+s∑j=1√|Bj|r∑i=1|Ai| ≤|B|⋅r√|A|/r+|A|⋅s√|B|/s ≤4m−1/5|A||B|.

With the tools above at hand, we can now prove the rainbow matching lemma.

Proof of Lemma 2.2. We will assume that is sufficiently small and is sufficiently large. Note that condition 3 implies that and hence .

Set and for . We first split the colours randomly as follows: for each colour independently, choose a label at random by choosing with probability . Let be the random subgraph of consisting of all edges whose colour set has been completely labelled with .

We first record some important properties of these subgraphs. With high probability, for every vertex and each label , we have

 dGi(u)=(1±2ϵ)ptid. (3.3)

This is because is the sum of independent Bernoulli variables and its expectation is , so the Chernoff bound (Lemma 2.5) implies that

 P[|dGi(u)−ptidG(u)|≥n2/3]≤2exp(−2n1/3).

Moreover, by Lemma 3.4, with high probability, for all and all sets and of size at least , we have

 eGi(A′,B′)=ptieG(A′,B′)+O(n11/6). (3.4)

By the probabilistic method, there exist graphs which have all of the above properties. We will find in an almost perfect rainbow matching, and then use to turn this into a perfect rainbow matching. For the second step, we will need the following “expansion” property of the graphs . (This is the property which allows us to have the asymptotically optimal size condition in 3.)

1. [label=()]

2. For any set (and similarly any ) of size at least , there are at least vertices which have at least neighbours in .

To see this, let be the set of vertices which have less than neighbours in , and let be the set of vertices which have more than neighbours in . By (3.3), there are at least edges going out of . By definition of , at most of these edges go to a vertex in . Moreover, we have , as otherwise we can use (3.4) in bounding

 |T+|⋅(1+ϵ)pti|S|≤eGi(T+,S)≤pti|T+||S|+O(n11/6)

to reach a contradiction. Hence, at least of the edges leaving go to vertices which are neither in nor in . Since each vertex not in has at most neighbours in , there must be at least

 (1−α/5)ptid|S|(1+ϵ)pti|S|≥(1−α/2)d

vertices where these edges go to. Each of these vertices is not in and hence has at least neighbours in .

Now, we begin with the construction of the matching. In the first step, we find an almost-perfect rainbow matching in . By (3.3), we know that every vertex has degree in . By condition 2, all colours have degree at most . Since