The complexity of perfect matchings and packings in dense hypergraphs

Given two $k$-graphs $H$ and $F$, a perfect $F$-packing in $H$ is a collection of vertex-disjoint copies of $F$ in $H$ which together cover all the vertices in $H$. In the case when $F$ is a single edge, a perfect $F$-packing is simply a perfect matching. For a given fixed $F$, it is often the case that the decision problem whether an $n$-vertex $k$-graph $H$ contains a perfect $F$-packing is NP-complete. Indeed, if $k \geq 3$, the corresponding problem for perfect matchings is NP-complete whilst if $k=2$ the problem is NP-complete in the case when $F$ has a component consisting of at least $3$ vertices. In this paper we give a general tool which can be used to determine classes of (hyper)graphs for which the corresponding decision problem for perfect $F$-packings is polynomial time solvable. We then give three applications of this tool: (i) Given $1\leq \ell \leq k-1$, we give a minimum $\ell$-degree condition for which it is polynomial time solvable to determine whether a $k$-graph satisfying this condition has a perfect matching; (ii) Given any graph $F$ we give a minimum degree condition for which it is polynomial time solvable to determine whether a graph satisfying this condition has a perfect $F$-packing; (iii) We also prove a similar result for perfect $K$-packings in $k$-graphs where $K$ is a $k$-partite $k$-graph. For a range of values of $\ell,k$ (i) resolves a conjecture of Keevash, Knox and Mycroft whilst (ii) answers a question of Yuster in the negative. In many cases our results are best possible in the sense that lowering the minimum degree condition means that the corresponding decision problem becomes NP-complete.

Given two k-graphs H and F , a perfect F -packing in H is a collection of vertex-disjoint copies of F in H which together cover all the vertices in H. In the case when F is a single edge, a perfect F -packing is simply a perfect matching. For a given fixed F , it is often the case that the decision problem whether an n-vertex k-graph H contains a perfect F -packing is NP-complete. Indeed, if k ≥ 3, the corresponding problem for perfect matchings is NP-complete [17,7] whilst if k = 2 the problem is NP-complete in the case when F has a component consisting of at least 3 vertices [14]. In this paper we give a general tool which can be used to determine classes of (hyper)graphs for which the corresponding decision problem for perfect F -packings is polynomial time solvable. We then give three applications of this tool: (i) Given 1 ≤ ≤ k−1, we give a minimum -degree condition for which it is polynomial time solvable to determine whether a k-graph satisfying this condition has a perfect matching; (ii) Given any graph F we give a minimum degree condition for which it is polynomial time solvable to determine whether a graph satisfying this condition has a perfect F -packing; (iii) We also prove a similar result for perfect K-packings in k-graphs where K is a k-partite k-graph. For a range of values of , k (i) resolves a conjecture of Keevash, Knox and Mycroft [20]; (ii) answers a question of Yuster [47] in the negative; whilst (iii) generalises a result of The question of whether a given k-graph H contains a perfect matching is one of the most fundamental problems in combinatorics. In the graph case k = 2, Tutte's Theorem [46] gives necessary and sufficient conditions for H to contain a perfect matching, and Edmonds' Algorithm [5] finds such a matching in polynomial time. On the other hand, the decision problem whether a k-graph contains a perfect matching is famously NP-complete for k ≥ 3 (see [17,7]).
An important generalisation of the notion of a perfect matching is that of a perfect packing: Given two k-graphs H and F , an F -packing in H is a collection of vertex-disjoint copies of F in H. An F -packing is called perfect if it covers all the vertices of H. Perfect F -packings are also referred to as F -factors or perfect F -tilings. Note that perfect matchings correspond to the case when F is a single edge. Hell and Kirkpatrick [14] showed that the decision problem whether a graph G has a perfect F -packing is NP-complete precisely when F has a component consisting of at least 3 vertices.
In light of the aforementioned complexity results, there has been significant attention to determine classes of (hyper)graphs for which the respective decision problems are polynomial time solvable. A key contribution of this paper is to provide a general tool (Theorem 3.1) that can be used to obtain such results. For this result we need to introduce several concepts so we defer its statement until Section 3.4. However, roughly speaking, for any k-graph F , Theorem 3.1 yields a general class of k-graphs within which we do have a complete characterisation of those k-graphs that contain a perfect F -packing. We then give three applications of Theorem 3.1, which we describe below. In particular, each of our applications convey an underlying theme: In each case, the class of (hyper)graphs H we consider are those satisfying some minimum degree condition which ensures an almost perfect matching or packing M (i.e. M covers all but a constant number of the vertices of H). Thus, in each application we show that we can detect the 'last obstructions' to having a perfect matching or packing efficiently. for all 1 ≤ ≤ k − 1. In recent years Conjecture 1.1 (and its exact counterpart) has received substantial attention [1,4,9,10,21,22,27,31,34,36,37,39,40,[43][44][45]. In particular, the exact threshold is known for all such that 0.42k ≤ ≤ k−1 as well as for a handful of other values of (k, ). For example, Rödl, Ruciński and Szemerédi [40] determined the codegree threshold for this problem for sufficiently large k-graphs H on n vertices. This threshold is n/2 − k + C where C ∈ {3/2, 2, 5/2, 3} depends on the value of n and k.
Such results give us classes of dense k-graphs for which we are certain to have a perfect matching. This raises the question of whether one can lower the minimum -degree condition in Conjecture 1.1 whilst still ensuring it is decidable in polynomial time whether such a k-graph H has a perfect matching: Let PM(k, , δ) denote the problem of deciding whether there is a perfect matching in a given k-graph on n vertices with minimum -degree at least δ n k− . Write PM(k, δ) := PM(k, k − 1, δ).
The above mentioned result of Rödl, Ruciński and Szemerédi [40] implies that PM(k, 1/2) is in P. On the other hand, for k ≥ 3 Szymańska [42] proved that for δ < 1/k the problem PM(k, δ) admits a polynomial-time reduction to PM(k, 0) and hence PM(k, δ) is also NP-complete. Karpiński, Ruciński and Szymańska [18] proved that there exists an > 0 such that PM(k, 1/2 − ) is in P; they also raised the question of determining the complexity of PM(k, δ) for δ ∈ [1/k, 1/2). For any δ > 1/k, Keevash, Knox and Mycroft [20] recently proved that PM(k, δ) is in P . Then very recently this question was completely resolved by the first author [12] who showed that PM(k, δ) is in P for any δ ≥ 1/k.
Note that the minimum codegree of the space barrier construction H 2 above is δ k−1 (H 2 ) = n/k−1. So in the case of minimum codegree, the threshold at which PM(k, δ) 'switches' from NP-complete to P corresponds to this space barrier. This leads to the question whether the same phenomenon occurs in the case of minimum -degree for ≤ k − 2. In support of this, Szymańska [42] proved that PM(k, , δ) is NP-complete when δ < 1 −(1 −1/k) k− . This led Keevash, Knox and Mycroft [20] to pose the following conjecture. [20]). PM(k, , δ) is in P for every δ > 1 − (1 − 1/k) k− .

Conjecture 1.2 (Keevash, Knox and Mycroft
As an application of Theorem 3.1 we verify Conjecture 1.2 in a range of cases. To state our result, we first must introduce the notion of a perfect fractional matching: Let H be a k-graph on n vertices. A fractional matching in H is a function w : E(H) → [0, 1] such that for each v ∈ V (H) we have that e v w(e) ≤ 1. Then e∈E(H) w(e) is the size of w. If the size of the largest fractional matching w in H is n/k then we say that w is a perfect fractional matching. Given k, ∈ N such that ≤ k − 1, define c * k, to be the smallest number c such that every k-graph H on n vertices with δ (H) ≥ (c + o(1)) n− k− contains a perfect fractional matching. We can now state our complexity result for perfect matchings.
Here ln denotes the natural logarithm function.) Altogether, this implies the following.

Perfect packings in graphs
Several complexity problems for perfect packings in graphs have received attention. Given a graph F , we write |F | for its order and χ(F ) for its chromatic number. For approximating the size of a maximal F -packing, Hurkens and Schrijver [15] gave an (|F |/2 + )-approximation algorithm (where > 0 is arbitrary) which runs in polynomial time. On the other hand, Kann [16] proved that the problem is APX-hard if F has a component which contains at least three vertices. (In other words, it is impossible to approximate the optimum solution within an arbitrary factor unless P=NP.) In contrast, the results in [14] imply that the remaining cases of the problem can be solved in polynomial time.
The following classical result of Hajnal and Szemerédi [8] characterises the minimum degree that ensures a graph contains a perfect K r -packing. Theorem 1.5 (Hajnal and Szemerédi [8]). Every graph G whose order n is divisible by r and whose minimum degree satisfies δ(G) ≥ (1 − 1/r)n contains a perfect K r -packing.
By considering a complete r-partite graph G with vertex classes of almost equal size, one can see that the minimum degree condition in Theorem 1.5 cannot be lowered. Kierstead, Kostochka, Mydlarz and Szemerédi [23] gave a version of Theorem 1.5 which also yields a fast (polynomial time) algorithm for producing the perfect K r -packing.
Up to an error term, the following theorem of Alon and Yuster [2] generalises Theorem 1.5. Let M (n) be the time needed to multiply two n by n matrices with 0, 1 entries. (Here the entries are viewed as elements of Z.) Determining M (n) is a challenging problem in theoretic computer science, and the best known bound of M (n) = O(n 2.3728639 ) was obtained by Le Gall [32]. Theorem 1.6 (Alon and Yuster [2]). For every γ > 0 and each graph F there exists an integer n 0 = n 0 (γ, F ) such that every graph G whose order n ≥ n 0 is divisible by |F | and whose minimum degree is at least (1 − 1/χ(F ) + γ)n contains a perfect F -packing. Moreover, there is an algorithm which finds this F -packing in time O(M (n)).
In [2], they also conjectured that the error term γn in Theorem 1.6 can be replaced by a constant C(F ) > 0 depending only on F ; this has been verified by Komlós, Sárközy and Szemerédi [25]. Theorem 1.7 (Komlós, Sárközy and Szemerédi [25]). For every graph F there exist integers C < |F | and n 0 = n 0 (F ) such that every graph G whose order n ≥ n 0 is divisible by |F | and whose minimum degree is at least (1 −1/χ(F ))n +C contains a perfect F -packing. Moreover, there is an algorithm which finds this F -packing in time O(nM (n)).
As observed in [2], there are graphs F for which the constant C(F ) cannot be omitted completely. On the other hand, there are graphs F for which the minimum degree condition in Theorem 1.7 can be improved significantly [19,3], by replacing the chromatic number with the critical chromatic number. The critical chromatic number χ cr (F ) of a graph F is defined as (χ(F ) − 1)|F |/(|F | − σ(F )), where σ(F ) denotes the minimum size of the smallest colour class in a colouring of F with χ(F ) colours. Note that χ(F ) − 1 < χ cr (F ) ≤ χ(F ) and the equality holds if and only if every χ(F )-colouring of F has equal colour class sizes. If χ cr (F ) = χ(F ), then we call F balanced, otherwise unbalanced. Komlós [24] proved that one can replace χ(F ) with χ cr (F ) in Theorem 1.7 at the price of obtaining an F -packing covering all but n vertices. He also conjectured that the error term n can be replaced with a constant that only depends on F [24]; this was confirmed by Shokoufandeh and Zhao [41] (here we state their result in a slightly weaker form). [41]). For any F there is an n 0 = n 0 (F ) so that if G is a graph on n ≥ n 0 vertices and minimum degree at least (1 − 1/χ cr (F ))n, then G contains an F -packing that covers all but at most 5|F | 2 vertices.

Theorem 1.8 (Shokoufandeh and Zhao
Then the question is, for which F can we replace χ(F ) with χ cr (F ) in Theorem 1.7? Kühn and Osthus [26,29] answered this question completely. To state their result, we need some definitions. Write k := χ(F ). Given a k-colouring c, let x 1 ≤ · · · ≤ x k denote the sizes of the colour classes of c and put D( In particular we have χ cr (F ) ≤ χ * (F ). Theorem 1.9 (Kühn and Osthus [26,29]). There exist integers C = C(F ) and n 0 = n 0 (F ) such that every graph G whose order n ≥ n 0 is divisible by |F | and whose minimum degree is at least (1 − 1/χ * (F ))n + C contains a perfect F -packing.
Theorem 1.9 is best possible in the sense that the degree condition cannot be lowered up to the constant C (there are also graphs F such that the constant cannot be omitted entirely). Moreover, this also implies that, one can replace χ(F ) with χ cr (F ) in Theorem 1.7 if and only if hcf(F ) = 1. When hcf(F ) = 1 certain divisibility barrier constructions show that the minimum degree condition in Theorem 1.9 (and thus Theorem 1.7) is best possible up to the additive constant C (see [29]). On the other hand, the following space barrier construction shows that one cannot replace χ * (F ) with anything smaller than χ cr (F ) in Theorem 1.9; that is, when hcf(F ) = 1, Theorem 1.9 is best possible up to the additive constant C: Let G be the complete χ(F )-partite graph on n vertices with σ(F )n/|F | − 1 vertices in one vertex class, and the other vertex classes of sizes as equal as possible. Then δ(G) = (1 − 1/χ cr (F ))n − 1 and G does not contain a perfect F -packing. Now let us return to the algorithmic aspect of this problem. Let Pack(F, δ) be the decision problem of determining whether a graph G whose minimum degree is at least δ|G| contains a perfect F -packing. When F contains a component of size at least 3, the result of Hell and Kirkpatrick [14] shows that Pack(F, 0) is NP-complete. In contrast, Theorem 1.9 gives that Pack(F, δ) is (trivially) in P for any δ ∈ (1 − 1/χ * (F ), 1]. In [26], Kühn and Osthus showed that Pack(F, δ) is NP-complete for any δ ∈ [0, 1 − 1/χ cr (F )) if F is a clique of size at least 3 or a complete k-partite graph such that k ≥ 2 and the size of the second smallest vertex class is at least 2.
Our next result provides an algorithm showing that Pack(F, δ) is in P when δ ∈ (1 − 1/χ cr (F ), 1], which gives a negative answer to Problem 1.10 (as seen for any F such that χ cr (F ) < χ * (F )). In fact, this gives the first nontrivial polynomial-time algorithm for the decision problem Pack(F, δ). In particular, it eliminates the aforementioned hardness gap for unbalanced complete multi-partite graphs F with hcf(F ) = 1 almost entirely. Theorem 1.11. For any m-vertex k-chromatic graph F and δ ∈ (1 − 1/χ cr (F ), 1], Pack(F, δ) is in P . That is, for every n-vertex graph G with minimum degree at least δn, there is an algorithm with running time O(n max{2 m k−1 −1 m+1, m(2m−1) m } ), which determines whether G contains a perfect F -packing.
In view of the aforementioned result of [26], Theorem 1.11 is asymptotically best possible if F is a complete k-partite graph such that k ≥ 2 and the size of the second smallest cluster is at least 2 (note that when F is balanced, the result is included in Theorem 1.6). On the other hand, Theorem 1.11 complements Theorem 1.8 in the sense that when the minimum degree condition guarantees an F -packing that covers all but constant number of vertices, we can detect the 'last obstructions' efficiently.
We remark that Theorem 1.11 also appears in a conference paper of the first author [13].

Perfect packings in hypergraphs
Over the last few years there has been an interest in obtaining degree conditions that force a perfect F -packing in k-graphs where k ≥ 3. In general though, this appears to be a harder problem than the graph version. Indeed, far less is known in the hypergraph case. See a survey of Zhao [48] for an overview of the known results in the area. Our final application of Theorem 3.1 is related to a recent general result of Mycroft [35].
Given a k-graph F and an integer n divisible by |F |, we define the threshold δ(n, F ) as the smallest integer t such that every n-vertex k-graph H with δ k−1 (H) ≥ t contains a perfect F -packing. Let F be a k-partite k-graph on vertex set U with at least one edge. Then a k-partite realisation of F is a partition of U into vertex classes U 1 , . . . , U k so that for any e ∈ E(F ) and 1 ≤ j ≤ k we have |e ∩ U j | = 1. Define where in each case the union is taken over all k-partite realisations χ of F into vertex classes U 1 , . . . , U k of F . Then gcd(F ) is defined to be the greatest common divisor of the set and thus in particular, σ(F ) ≤ 1/k. Mycroft [35] proved the following: i fg c d ( F ) = 1; max{σ(F )n, n/p} + o(n) if gcd(S(F )) = 1 and gcd(F ) = d > 1, (1.1) where p is the smallest prime factor of d. Moreover, equality holds in (1.1) for all complete k-partite k-graphs F , as well as a wide class of other k-partite k-graphs.
Mycroft [35] also showed that minimum codegree of at least σ(F )n +o(n) in an n-vertex k-graph H ensures an F -packing covering all but a constant number of vertices. The next two results show that above this degree threshold, one can determine in polynomial time whether H contains a perfect F -packing, whilst below the threshold the problem is NP-complete (for complete k-partite k-graphs F ). Given δ > 0 and a k-graph F , let Pack(F, δ) be the decision problem of determining whether a k-graph H whose minimum codegree is at least δ|H| contains a perfect F -packing.  Note that when F is just an edge, a perfect F -packing is simply a perfect matching. Further, in this case σ(F ) = 1/k. Thus, Theorem 1.13 is a generalisation of the perfect matching result of Keevash, Knox and Mycroft [20].

A general tool for complexity results
To prove the results mentioned above, we introduce a general structural theorem, Theorem 3.1. Given any k-graph F , Theorem 3.1 considers k-graphs H whose minimum -degree is sufficiently large so as to ensure H contains an almost perfect F -packing (that is an F -packing covering all but a constant number of vertices in H). To state Theorem 3.1 we introduce a coset group which, loosely speaking, is defined with respect to the 'distribution' of copies of F in H. In particular, Theorem 3.1 states that if this coset group Q has bounded size then we have a necessary and sufficient condition for H containing a perfect F -packing. This condition can be easily checked in polynomial time. This means if we have a class of k-graphs H (i) each of whose minimum -degree is sufficiently large and; (ii) each such H has a corresponding coset group Q of bounded size, then we can determine in polynomial time whether an element H in this class has a perfect F -packing.
Thus, in applications of Theorem 3.1 the key goal is to determine whether the corresponding coset groups have bounded size. In our applications to Theorems 1.11 and 1.13 all k-graphs H considered will have a corresponding coset group Q of bounded size. On the other hand, to prove Theorem 1.3 we show that a hypergraph H under consideration must have a corresponding coset group Q of bounded size, or failing that, must have a perfect matching.
The approach of using these auxiliary coset groups as a tool for such complexity results was also used in [20,12]; note that these applications were for perfect matchings in hypergraphs of large minimum codegree. Theorem 3.1 provides a generalisation of this approach. Indeed, Theorem 3.1 is applicable to perfect matching and packing problems in (hyper)graphs of large minimum -degree for any . As such, we suspect Theorem 3.1 could have many more applications in the area.
The paper is organised as follows. In the next section we prove Theorem 1.12. In Section 3 we introduce the general structural theorem (Theorem 3.1) as well as some notation and definitions. We prove Theorem 3.1 in Sections 4 and 5. In Sections 6 and 7 we introduce some tools that are useful for the applications of Theorem 3.1. We then prove Theorems 1.3, 1.11 and 1.13 in Sections 8, 9 and 10 respectively.

Proof of the hardness result
In this section we prove Theorem 1.12.
Proof of Theorem 1.12. Our proof resembles the one of Szymańska [42,Theorem 1.7] and we also use the following result from it. Let PM lin (k) be the subproblem of PM(k, 0) restricted to k-uniform hypergraphs which are linear, that is, any two edges share at most one vertex. Then it is shown in [42] . . , a k ) be the complete k-partite k-graph of order m with vertex classes of size a 1 ≤ · · · ≤ a k . We may assume that a k ≥ 2 as otherwise K is just a single edge and Pack(K, δ) is NP-complete for δ ∈ [0, 1/k) as shown in [42]. We prove the theorem by the following reductions.
Reduction (a). In fact, we will show that PM lin (k)≤PM lin (k + 1) for any k ≥ 3. Let H be a linear k-graph with n vertices and s edges. We construct a linear (k + 1)-graph G by taking k + 1 disjoint copies H i of H, i ∈ [k + 1] and for every edge e in each copy On the other hand assume that G has a perfect matching Therefore H also has a perfect matching.
Reduction (b). Given a linear m-graph H we build a k-graph G by replacing each edge of H with a copy of K. If H has a perfect matching then G has a perfect K-packing. In turn, if G has a perfect K-packing, then by the linearity of H, each copy of K corresponds to a single edge of H and therefore the K-packing corresponds to a perfect matching of H. In fact, since K is complete k-partite, there exists an ordering e 1 , . . . , e t of E(K) (e.g., the lexicographic ordering) such that for any 2 ≤ i ≤ t, there exists 1 ≤ j ≤ i − 1 such that |e i ∩ e j | ≥ 2. Then by the linearity of H, each copy of K corresponds to a single edge of H.
Reduction (c). Let γ := σ(K) − δ = a 1 /m − δ and thus γ > 0. To achieve this, for each instance H of Pack(K, 0) with n vertices such that m | n, we define a graph H as follows. Let H 0 = H 0 (k, n, γ) be a k-graph, in which the vertex set is the union of two disjoint sets A ∪ B, such that |A| = a 1 n/γ and |B| = (m − a 1 ) n/γ . The edge set of H 0 consists of all k-vertex sets of A ∪ B which have a non-empty intersection with A. Observe that δ k−1 (H 0 ) = |A| and H 0 has a perfect K-packing (in which each copy of K contains a 1 vertices in A and m − a 1 vertices in B). Then let H be the k-graph such If H has a perfect K-packing, so does H . Now suppose that H does not have a perfect K-packing and H has a perfect K-packing M . This means that there exists a copy of K in M with its vertex set denoted by K , such that , so the rest of the vertices of B cannot be covered completely by M , a contradiction. 2

The general structural theorem
In order to state our general structural theorem, Theorem 3.1, we will now introduce some definitions and notation.

Almost perfect packings
contains an F -packing covering all but at most D vertices. We write δ(k, , D) for δ(F, , D) when F is a single edge.

Lattices and solubility
One concept needed to understand the statement and proof of Theorem 3.1 is that of lattices and solubility introduced by Keevash, Knox and Mycroft [20]. Let H be an n-vertex k-graph. We will work with a vertex partition P = {V 1 , . . . , V d } of V (H) for some integer d ≥ 1. In this paper, every partition has an implicit ordering of its parts. The index vector i P (S) ∈ Z d of a subset S ⊆ V (H) with respect to P is the vector whose coordinates are the sizes of the intersections of S with each part of P, namely, We say that v ∈ Z d is an r-vector if it has non-negative coordinates and |v| = r.
Let F be an m-vertex k-graph and let μ > 0. Define I μ P,F (H) to be the set of all i ∈ Z d such that H contains at least μn m copies of F with index vector i and let L μ Given a partition P of d parts, we write L d max for the lattice generated by all m-vectors.

Reachability and good partitions
Let F be an m-vertex k-graph and let H be an n-vertex k-graph. We say that two We refer to such a set S as a reachable (im − 1)-set for u and v. We say a vertex set

Statement of the general structural theorem
With these definitions in hand, we are now able to state the general structural theorem. Throughout the paper, we write 0 < α β γ to mean that we can choose the constants α, β, γ from right to left. More precisely, there are increasing functions f and g such that, given γ, whenever we choose some β ≤ f (γ) and α ≤ g(β), all calculations needed in our proof are valid. Hierarchies of other lengths are defined in the obvious way.
Then H contains a perfect F -packing if and only if (P, At first sight Theorem 3.1 may seem somewhat technical. In particular, it may not be clear which roles conditions (i)-(iii) play. We will explain this in more detail now.
In the proof of (the backward implication of) Theorem 3.1 we will utilise the absorbing method. This technique was initiated by Rödl, Ruciński and Szemerédi [38] and has proven to be a powerful tool for finding spanning structures in graphs and hypergraphs. Fix an integer i > 0 and a k-

and both H[T ] and H[T ∪ S]
contain perfect F -packings. Informally, we will refer to T as an absorbing set for S and say T absorbs S.
Often in proofs employing the absorbing method the goal is to find some small set A such that for any very small set of vertices S in H, A absorbs S. In particular, if one could guarantee such a set A in Theorem 3.1 then we would ensure a perfect F -packing: By (i), H \ A would have an almost perfect F -packing. Then A can be used to absorb the uncovered vertices to obtain a perfect F -packing.
Not all k-graphs satisfying the hypothesis of Theorem 3.1 will have a perfect F -packing; so one cannot obtain such a set A in general. Instead, in the proof of Theorem 3.1 we will apply the lattice-based absorbing method developed recently by the first author [12]: What one can always guarantee in our case is a small family of absorbing sets F abs with the property that for every m-vertex set S ⊆ V (H) such that i P (S) ∈ I μ P,F (H), there are many sets in F abs that do absorb S. This is made precise in Lemma 4.1 in Section 4. We remark that to obtain F abs it was crucial that condition (ii) in Theorem 3.1 holds.
for each i, then by definition of F abs we can absorb the vertices in U to obtain a perfect F -packing in H. To find such a partition of U we certainly would need that i P (U ) ∈ L μ P,F (H). This is where the property that (P, L μ P,F (H)) is q-soluble is vital: by definition this allows us to find an F -packing M 1 of size at most q such Roughly speaking, the idea is that by removing the vertices of M 1 from H we now have a k-graph where (by following the steps outlined above) we do obtain a set of uncovered vertices U that can be fully absorbed using the family F abs . This step is a little involved; that is, some careful refinement of the almost perfect F -packing is still needed to ensure there is a partition S 1 , . . . , S s of U such that i P (S i ) ∈ I μ P,F (H) for each i. Condition (iii) is applied in both the forward and backward implication of Theorem 3.1. In particular, this is precisely the condition required to show that if H has a perfect F -packing then (P, L μ P,F (H)) is q-soluble. In the next section we prove the absorbing lemma and in Section 5 we prove Theorem 3.1.

Absorbing lemma
The following result guarantees our collection F abs of absorbing sets in the proof of Theorem 3.1. Proof. Our first task is to prove the following claim. Since the number of existing vertices is at most tm 2 + m, we have at least β 2 n tm−1 choices for such (tm − 1)-sets in each step. Note that W ∪ T 1 ∪ · · · ∪ T m is an absorbing set for S. First, it contains a perfect F -packing because each also contains a perfect F -packing because F is a copy of F and each T i ∪ {y i } for i ∈ [m] spans t vertex-disjoint copies of F . There were at least μ 2 n m choices for W and at least β 2 n tm−1 choices for each T i . Thus we find at least We pick a family F of tm 2 -sets by including every tm 2 -subset of V (H) with probability p = cn −tm 2 log n independently, uniformly at random. Then the expected number of elements in F is p n tm 2 ≤ c tm 2 log n and the expected number of intersecting pairs of tm 2 -sets is at most Then by Markov's inequality, with probability at least 1 − 1/(tm 2 ) − o (1), F contains at most c log n sets and they are pairwise vertex disjoint. For every m-set S with i P (S) ∈ I μ P,F (H), let X S be the number of absorbing sets for S in F. Then by Claim 4.2, E(X S ) ≥ pμβ m+1 n tm 2 = μβ m+1 c log n.

Proof of the backward implication of Theorem 3.1
Suppose I is a set of m-vectors of Z d and J is a (finite) set of vectors such that any i ∈ J can be written as a linear combination of vectors in I, namely, there exist a v (i) ∈ Z for all v ∈ I, such that We denote by C(d, m, I, J) as the maximum of |a v (i)|, v ∈ I over all i ∈ J.
The proof of the backward implication of Theorem 3.1 consists of a few steps. We first fix an F -packing M 1 , a q-solution of (P, L μ P,F (H)). We apply Lemma 4.1 to H and get a family F abs consisting of at most c log n disjoint tm 2 -sets. Let F 0 be the subfamily of F abs that do not intersect V (M 1 ). Next we find a set M 2 of disjoint copies of F , which includes (constantly) many copies of F for each m-vector in I μ P,F (H). Now by definition of δ(F, , D) we find an F -packing M 3 covering all but a set U of at most D vertices. The remaining job is to 'absorb' the vertices in U . Roughly speaking, by the solubility condition, we can release some copies of F in some members of F 0 and M 3 and add their vertices to U , such that the resulting set Y ⊇ U of uncovered vertices satisfies that i P (Y ) ∈ L μ P,F (H). Furthermore, by releasing some copies of F in M 2 and add their vertices to U , we can partition the new set of uncovered vertices as a collection of m-sets S such that i P (S) ∈ I μ P,F (H) for each S. Then we can finish the absorption by the property of F 0 .
Proof of the backward implication of Theorem 3.1. Define an additional constant C > 0 so that Let H be as in the statement of the theorem. Moreover, assume that (P, L μ P,F (H)) is q-soluble. We first apply Lemma 4.1 to H and get a family F abs consisting of at most c log n disjoint tm 2 -sets such that every m-set S of vertices with i P (S) ∈ I μ P,F (H) has at least √ log n absorbing (F, tm 2 )-sets in F abs . Since (P, L μ P,F (H)) is q-soluble, there exists an F -packing M 1 of size at most q such that i P (V (H) \ V (M 1 )) ∈ L μ P,F (H). Note that V (M 1 ) may intersect V (F abs ) in at most qm absorbing sets of F abs . Let F 0 be the subfamily of F abs obtained from removing the tm 2 -sets that intersect V (M 1 ). Let M 0 be the perfect F -packing on V (F 0 ) that is the union of the perfect F -packings on each member of F 0 . Note that every m-set S of vertices with i P (S) ∈ I μ P,F (H) has at least √ log n − qm absorbing sets in F 0 . Next we want to 'store' some copies of F for each m-vector in I μ P,F (H) for future use.
Proof. Assume to the contrary that F 1 , . . . , F p ∈ M 0 ∪ M 3 is a minimum set of copies of F such that (5.1) holds and p ≥ q. Consider the p + 1 partial sums i∈[j] R Q (V (F i )) for j = 0, 1, . . . , p, where the sum equals 0 + L μ P,F (H) when j = 0. Since |Q| ≤ q, two of the partial sums must be equal, that is, there exist 0 ≤ p 1 < p 2 ≤ p such that . So we get a smaller collection of copies of F in M 0 ∪ M 3 such that (5.1) holds, a contradiction. 2 We now complete the perfect F -packing by absorption. Since i P (Y ) ∈ L μ P,F (H), we have the following equation where a v ∈ Z for all v ∈ I μ P,F (H). Since |Y | ≤ qm + D, by the definition of C , we have |a v | ≤ C for all v ∈ I μ P,F (H). Noticing that a v may be negative, we can assume

This equation means that given a family
Since c v ≤ C for all v and V (M 2 ) ∩Y = ∅, we can choose the family F as a subset of M 2 . In summary, starting with the F -packing M 0 ∪M 1 ∪M 2 ∪M 3 leaving U uncovered, we delete the copies F 1 , . . . , F of F from M 0 ∪ M 3 given by Claim 5.1 and then leave Y = i∈[p] V (F i ) ∪ U uncovered. Then we delete the family F of copies of F from M 2 and leave V (F) ∪ Y uncovered. Finally, we regard V (F) ∪ Y as the union of at most m+d−1 d C + qm + D ≤ √ log n/2 m-sets S with i P (S) ∈ I μ P,F (H). Note that by definition, Y may intersect at most qm + D absorbing sets in F 0 , which cannot be used to absorb those sets we obtained above. Since each m-set S has at least √ log n − qm > √ log n/2 + qm + D absorbing (F, tm 2 )-sets in F 0 , we can greedily match each S with a distinct absorbing (F, tm 2 )-set F S ∈ F 0 for S. Replacing the F -packing on V (F S ) in M 0 by the perfect F -packing on H[F S ∪ S] for each S gives a perfect F -packing in H. 2

Useful tools
In this section we collect together some results that will be used in our applications of Theorem 3.1. When considering -degree together with -degree for some = , the following proposition is very useful (the proof is a standard counting argument, which we omit).
For the statements of the next three results, recall the definitions introduced in Sec- The following lemma gives us a sufficient condition for ensuring a partition P = Next we prove Lemma 6.3, whose proof is almost identical to the proof of [12, Lemma 3.8].
Proof of Lemma 6.3. Let := α/c. We choose constants satisfying the following hierarchy Let F and H be as in the statement of the lemma. Throughout this proof, given v ∈ V (H) and i ∈ [c − 1], we write Ñ F,β i ,2 i (v, H) as Ñ i (v) for short. Note that for We also write 2 i -reachable (or 2 i -closed) for (F, β i , 2 i )-reachable (or (F, β i , 2 i )-closed). By Proposition 6.4 and the choice of β i s, we may assume that We may assume that there are two vertices in S that are not 2 c−1 -reachable to each other, as otherwise S is 2 c−1 -closed in H and we obtain the desired (trivial) partition P = {S}. Let r be the largest integer such that there exist v 1 , . . . , v r ∈ S such that no pair of them are 2 c+1−r -reachable in H. Note that r exists by our assumption and 2 ≤ r ≤ c. Fix such v 1 , . . . , v r ∈ S; by Proposition 6.4, we can assume that any pair of them are not 2 c−r -reachable in H. Consider Ñ c−r (v i ) for all i ∈ [r]. Then we have the following facts. Note that (ii) and |Ñ c−r (v i ) ∩S| ≥ |Ñ 0 (v i ) ∩S| ≥ δ n for i ∈ [r] imply that rδ n − r 2 n ≤ |S| ≤ n. So we have r ≤ (1 + c 2 )/δ . Since ≤ α δ , 1/c, we have r ≤ 1/δ and thus, Let U 0 := S \ (U 1 ∪ · · · ∪ U r ). By (i) and (ii), we have |U 0 | ≤ r 2 n. We will move each vertex of U 0 greedily to U i for some i ∈ [r]. For any v ∈ U 0 , since |(Ñ 0 (v) ∩ S) \ U 0 | ≥ δ n − |U 0 | ≥ r n, there exists i ∈ [r] such that v is 1-reachable to at least n vertices in U i . In this case we add v to U i (we add v to an arbitrary U i if there are more than one such i). Let the resulting partition of S be V 1 , . . . , V r . Note that we have Observe that in each V i , the 'farthest' possible pairs are those two vertices both from U 0 , which are 2 c−r+1 -reachable to each other. Thus, each V i is 2 c−r+1 -closed, so 2 c−1 -closed because r ≥ 2.
We estimate the running time as follows. First, for every two vertices u, v ∈ S, we determine if they are 2 i -reachable for 0 ≤ i ≤ c − 1. This can be done by testing if any In the following section we prove Theorem 1.3. Here we collect together some useful notation and results for this proof.
The following result is a weaker version of Lemma 5.6 in [30]. The next crucial result is an immediate consequence of Lemma 7.1 together with results from [9,11,40].
Summary of the proof of Theorem 7.2. Suppose ε > 0 and n ∈ N is sufficiently large. Consider an n-vertex k-graph H such that δ (H) ≥ (max{1/3, c * k, } + ε) n− k− . To prove the theorem we must show that H contains a matching covering all but at most k vertices.
Next suppose that k ≥ 4 and 2 ≤ ≤ k − 2. Then [11, Theorem 1.7] and [11, Proposition 1.11] together with Lemma 7.1 imply the following: every sufficiently large n -vertex k-graph H with k n and δ k−1 ( contains a matching covering all but at most k vertices. So with H as above we immediately obtain our desired matching if k n. If k | n then let H := H \ x for some x ∈ V (H) and set n : and thus H contains a matching M covering all but at most k vertices. Therefore since k | n this implies that M covers all but precisely k − 1 vertices in H , and therefore all but precisely k vertices in H, as desired.
The final case is when = 1. This case follows by Lemma 7.1 and the Strong Absorbing Lemma in [9,Lemma 2.4]. In particular, this uses that c * k,1 ≥ 1/2. 2 In fact, it is possible to show that δ(k, , k) = c * k, for any 1 ≤ ≤ k − 1, but Theorem 7.2 is enough for this paper.

Proof of Theorem 1.3
Let δ ∈ (δ * , 1] and define Let H be as in the statement of Theorem 1.3. Note that we may assume n ≥ n 0 and k | n since else the result is trivial (recall the use of big-O notation in the statement of the theorem). So and in particular, by Proposition 6.1, Notice that by (8.2), ( * ) Every set of three vertices of V (H) contains two vertices that are (α, 1)-reachable.
We now split the argument into two cases.
Our aim is to apply Theorem 3.1 to H. First, by Theorem 7.2 and (8.1), we have that δ (H) ≥ (δ(k, , k) + γ) n− k− . Second, by definition, P is an (E, β, 2, η/2)-good partition of V (H), where E is a k-graph on k vertices consisting of a single edge.
Second, assume that I μ P,E (H) contains exactly one element, say I μ P,E (H) = {(a, b)}, where a + b = k. Note that it must hold that a ≥ and b ≥ . Indeed, if a < , then the number of edges that contain an -set of index vector ( , 0) is at most kμn k . Thus, by averaging and since μ η 1/k, there exists an -set S of index vector ( , 0) such that d H (S) ≤ k kμn k / |V 1 | ≤ √ μn k− < δ (H), a contradiction. The same argument shows that b ≥ . Then for 0 ≤ 1 ≤ , let 2 = − 1 . By averaging, for each 0 ≤ 1 ≤ , there exists an -set S 1 of index vector ( 1 , 2 ) such that Recall the identity 0≤i≤t Since ≥ 2 and a, b ≥ , the above sum contains at least three terms. As μ γ That is, the case when I μ P,E (H) contains one element does not occur. Therefore we can apply Theorem 3.1 to H with D = q = k, t = 2 and c = η/2 and thus conclude that H contains a perfect matching if and only if (P, L μ P,E (H)) is k-soluble.
The algorithm. Now we state our algorithm. First, for every two vertices u, v ∈ V (H), we determine if they are (α, 1)-reachable, which can be done by testing if any (k − 1)-set is a reachable set in time O(n k−1 ). So this step can be done in time O(n k+1 ). Then we check if |Ñ α,1 (v, H)| ≥ ηn for every v ∈ V (H). With the reachability information, this can be tested in time O(n 2 ). If |Ñ α,1 (v, H)| < ηn for some v ∈ V (H), then we output PM and halt. Otherwise we run the algorithm with running time O(n 2k+1 ) provided by Lemma 6.3 and get a partition P. By Theorem 3.1, it remains to test if (P, L μ P,E (H)) is k-soluble. This can be done by testing whether any matching M of size at most k is a solution of (P, L μ P,E (H)), in time O(n k 2 ). If there is a solution M for (P, L μ P,E (H)), output PM; otherwise output NO. The overall running time is O(n k 2 ).

The perfect graph packing result
In this section we prove Theorem 1.11. Let F be an m-vertex k-chromatic graph. By the definition of χ cr (F ), we have We will apply the following variant of Lemma 6.2, which can be easily derived from the original version by defining a k-graph G where each k-set forms a hyperedge if and only if it spans a copy of K k in G. For any vertex u ∈ V (G), let W (u) denote the collection of (k − 1)-sets S such that S ⊆ N (u) and such that S spans a clique in G. For a set T ⊆ V (G), let N (T ) := v∈T N (v).
We apply Lemma 9.1 to prove the following result.
On the other hand, using the minimum degree condition, it is easy to see that |W (v)| ≥ 1 m k−1 n k−1 . Since γ 1/m, 1/k, we have The following proposition shows that |Q(P, L μ P,F (G))| is bounded from above. Proposition 9.3. Let t, r, k, m, n 0 ∈ N where k ≥ 2 and let β, μ, γ > 0 so that We need the following simple counting result, which, for example, follows from the result of Erdős [6] on supersaturation. (Note that this result of Erdős will be later applied, as Proposition 10.1, in the proof of Theorem 1.13.) Proposition 9.4. Given γ > 0, 1 , . . . , k ∈ N, there exists μ > 0 such that the following holds for sufficiently large n. Let T be an n-vertex graph with a vertex partition V 1 ∪ · · · ∪ V d . Suppose i 1 , . . . , i k ∈ [d] are not necessarily distinct and T contains at least γ n k copies of Then T contains at least μn 1 +···+ k copies of K (2) ( 1 , . . . , k ) whose jth part is contained in V i j for all j ∈ [k].
We write u j for the 'unit' 1-vector that has 1 in coordinate j and 0 in all other coordinates.
Proof of Proposition 9.3. Write L := L μ P,F (G). It suffices to show that for any element and v + L = v + L. In particular, the number of such v is at most (2m − 1) r . Since F is unbalanced, there exists a k-colouring with colour class sizes a 1 ≤ · · · ≤ a k and a 1 < a k . Set a := a k − a 1 < m.
Let P = {V 1 , . . . , V r } be the partition of V (G) given in the statement of the proposition. Define a graph P on the vertex set [r] such that (i, j) ∈ E(P ) if and only if e(G[V i , V j ]) ≥ γn 2 . We claim that if i and j are connected by a path in P , then it is easy to see that uv is contained in at least 1 m k−2 n k−2 copies of K k in G. So there are at least γn 2 · 1 m k−2 n k−2 / k 2 copies of K k in G intersecting both V i and V j . By averaging, there exists a k-array (i 1 , . . . , i k ), i j ∈ [r] where i 1 = i and i k = j such that G contains at least By applying Proposition 9.4 with i := a i for each i ∈ [k], we get that there are at least μn m copies of K (2) (a 1 , . . . , a k ) in G whose jth part is contained in V i j for all j ∈ [k]. We apply Proposition 9.4 again, this time with i := a i for all 2 ≤ i ≤ k − 1 and 1 := a k , k := a 1 and thus conclude that there are at least μn m copies of K (2) (a k , a 2 , . . . , a k−1 , a 1 ) (with a 1 and a k exchanged) in G whose jth part is contained in V i j for all j ∈ [k]. Taking subtraction of index vectors of these two types of copies gives that a(u i − u j ) ∈ L. Furthermore, note that if i and j are connected by a path in P , we can apply the argument above to every edge in the path and conclude that a(u i − u j ) ∈ L, so the claim is proved. We now distinguish two cases.
Case 1: k ≥ 3. In this case, we first show that P is connected. Indeed, we prove that for any bipartition A ∪ B of [r], there exists i ∈ A and j ∈ B such that (i, j) ∈ E(P ). Let V A := i∈A V i and V B := j∈B V j . Without loss of generality, assume that |V A | ≤ n/2.
)n, the number of edges in G that are incident to V A is at least where the last inequality follows since |B| ≤ r, |V A | ≥ |A|n/m and γ 1/m. By averaging, there exists i ∈ A and j ∈ B such that e(G[V i , V j ]) ≥ γn 2 and thus (i, j) ∈ E(P ).
We fix an arbitrary m-vector w ∈ L and let v 1 := v − (|v|/m)w. So |v 1 | = 0 and v 1 + L = v + L. Since P is connected, the claim above implies that for any i, j ∈ [r], a(u i − u j ) ∈ L.
We now apply the following algorithm to v 1 . Suppose v 1 i is the coordinate of v 1 with the largest absolute value. If |v 1 i | ≤ m − 1 we terminate the algorithm. Otherwise, since Note that still |v 1 | = 0 and |v 1 i | has decreased. We repeat this algorithm until we obtain a vector v = (v 1 , . . . , v r ) so that |v | = 0 and −(m − 1) ≤ v i ≤ m − 1 for all i ∈ [r]. Note that v was obtained from v 1 by repeatedly adding and subtracting elements of L to v 1 . Since initially v 1 + L = v + L we have that v + L = v + L, as desired.
Case 2: k = 2. In this case we cannot guarantee that P is connected (we may even have some isolated vertices). First let i be an isolated vertex in P . By the definition of P , we know that e( Applying Proposition 9.4 on V i shows that there are at least μn m copies of K (2) (a 1 , a 2 ) in gives that a 1 u i + a 2 u j ∈ L. So in both cases, for any component C in P , there exists an Consider the connected components C 1 , C 2 , . . . , C q of P , for some 1 ≤ q ≤ r. Let v 1 be obtained as follows: for each component C, we add to v a multiple of the vector w C such that 0 ≤ |v 1  Proof of Theorem 1.11. We first note that it suffices to prove Theorem 1.11 in the case when F is unbalanced. Indeed, if F is balanced then χ(F ) = χ cr (F ) and so the result follows (trivially) from Theorem 1.6.
The algorithm. Now we state the algorithm and estimate the running time. We run the algorithm with running time O(n 2 m k−1 −1 m+1 ) provided by Lemma 6.3 and obtain a partition P of V (G). By Theorem 3.1, it remains to test if (P, L μ P,F (G)) is (2m − 1) r -soluble. This can be done by testing whether any F -packing M of size at most (2m − 1) r is a q-solution of (P, L μ P,F (G)), in time O(n m(2m−1) r ) = O(n m(2m−1) m ). If there is a q-solution M for (P, L μ P,F (G)), output YES; otherwise output NO. The overall running time is O(n max{2 m k−1 −1 m+1, m(2m−1) m } ). 2

Packing k-partite k-uniform hypergraphs
In this section we prove Theorem 1.13. For this we will first collect together a few useful results. Throughout this section we consider a (not necessarily complete) k-partite k-graph F on m vertices, and let a be the minimum of the size of the smallest vertex class over all k-partite realisations of V (F ). Let K(F ) ⊇ F be a complete k-partite k-graph on m vertices such that the smallest vertex class has a vertices. We will also write σ(F ) := a/m. The next proposition is a supersaturation result of Erdős [6].
Proposition 10.1. Let η > 0, k, r ∈ N and let K := K (k) (a 1 , . . . , a k ) be the complete k-partite k-graph with a 1 ≤ · · · ≤ a k vertices in each class. There exists 0 < μ η such that the following holds for sufficiently large n. Let H be an k-graph on n vertices with a vertex partition V 1 ∪ · · · ∪ V r . Consider not necessarily distinct Then H contains at least μn a 1 +···+a k copies of K whose jth part is contained in We also use the following result of Mycroft [35,Theorem 1.5] which forces an almost perfect F -packing. The following proposition shows that Q(P, L μ P,F (H)) has bounded size.
By (10.1) and the above claim, we can apply Lemma 6.3 to H with the constants chosen at the beginning of the proof. We get a partition P = {V 1 , . . . , V r } of V (H) such that r ≤ m and for any i ∈ [r], |V i | ≥ (σ(F ) + γ/2 − α)n ≥ n/m and V i is (F, β, 2 m−1 )-closed in H. Thus, P is a (F, β, 2 m−1 , 1/m)-good partition of V (H).

Concluding remarks
In this paper we introduced a general structural theorem (Theorem 3.1) which can be used to determine classes of (hyper)graphs for which the decision problem for perfect F -packings is polynomial time solvable. We then gave three applications of this result. It would be interesting to find other applications of Theorem 3.1.
In light of Conjecture 1.2 it is likely that one can replace the condition that δ * = max{1/3, c * k, } in Theorem 1.3 with δ * = c * k, . Theorem 3.1 is likely to be useful for this. However, note that in the proof of Theorem 1.3, the condition δ * ≥ 1/3 ensured that the partition P of V (H) consisted of at most 2 vertex classes. We then showed that our hypergraph H contained a perfect matching or that the coset group Q had bounded size. In particular, since |P| ≤ 2 it was relatively straightforward to show that |Q| was bounded. However, if we no longer have that δ * ≥ 1/3 we may have that P consists of many classes. Thus, determining that Q has bounded size is likely to be substantially harder in this case.
In Theorems 1.3, 1.11 and 1.13 we provided algorithms for determining whether a hypergraph contains a perfect matching or packing. It would be interesting to obtain analogous results which produce a perfect matching or packing if such a structure exists.