Guillotine cutting is asymptotically optimal for packing consecutive squares

More than half a century ago Martin Gardner popularized a question leading to the benchmark problem of determining the minimum side length of a square into which the squares of sizes 1,2,⋯,n\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$1,2,\dots ,n$$\end{document} can be packed without overlap. Constructions are known for a certain range of n, and summing up the areas yields that a packing in a square of size smaller than N:=n(n+1)(2n+1)/6)\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$N:= \!\sqrt{n(n+1)(2n+1)/6)} $$\end{document} is not possible. Here we prove that an asymptotically minimal packing exists in a square of size N+cn+O(n)\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$N+cn+O(\!\sqrt{n})$$\end{document} with c<1\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$c<1$$\end{document}, and such a packing is achievable with guillotine-cuts. An improved construction is also given for the case where the constraint of guillotine cutting is dropped.


Introduction and results
The problem we deal with in this paper emerged from columns written by Martin Gardner in 1966 and1975 [5,6], where he popularized a previously unpublished question due to R. B. Britton. The problem is to pack the first n consecutive squares (i.e. the ones with edge lengths 1, . . . , n) into a smallest containing square (with integer edge Extended author information available on the last page of the article length). Here and throughout the paper we consider only the case where the squares have to be packed parallel to the axes (i.e. rotation is not allowed) and we have to pack them without overlapping. Other natural assumptions are that the squares are allowed to touch each other and that they cannot be split. For this problem, Gardner [6] listed the best possible (tight) results up to n = 17 (based on earlier works). An upper bound (U B) is best possible if it meets a valid lower bound.
The packing of consecutive squares has become a benchmark problem for general square packing problems, e.g. it is used to test more general rectangle packing algorithms [14,16,21]. Rectangle packing has been applied in VLSI design, and also can be used to model some real-world problems like scheduling, cutting stock and pallet loading problems. In most of these areas rotation of the rectangles is allowed; however, there are some problems, for example in scheduling, where rotation is forbidden.
The current best upper bounds for our problem can be found on the webpage [22], searching for the integer sequence A005842. There, the best known U B(n) values are listed till n = 56 (most of them are tight), where U B(n) is the upper bound for our problem with a given parameter n. The best lower bounds for large values of n come from the simple fact that we can get a fairly good estimate by rounding up the square root of the total area of the squares, i.e. in our case we get the value n(n + 1)(2n + 1)/6) . Tightness is not proved for the cases n = 38, 40, 42, 48, 52, 53 and 55, while the other values of U B(n) given in [22] are proved to be tight for 1 ≤ n ≤ 56. The latest results have been achieved by Hougardy [8]. He showed that U B(28) = 89, U B(32) = 108, U B(33) = 113, U B(34) = 118, and U B(47) = 190, and proved that these upper bounds are best possible; i.e., L B 0 + 1 is a valid matching lower bound in these cases. An interesting special case of the problem is n = 24, which was unsolved until 2004. As proved earlier [23], n = 24 is the unique non-trivial case where n(n+1)(2n+1) 6 is an integer. However, while L B 0 (24) = 70, the optimum is 71 as proved by Korf [15].
A related problem is to pack an arbitrary set of squares with a total area of at most 1 into a rectangle of minimum area. In this line of thinking it was proved in [17] that any rectangle of area 2 suffices, provided that its side lengths are not smaller than the largest square to be packed. A stronger upper bound can be derived from [13], stating that a covering rectangle with an area of at most √ 8/3 < 1.633 can be given for any input of this type. This result was further improved to 1.53 in [18], and to 1.4 in [7]. Moreover, several papers deal with higher dimension; see e.g. [1,12,19,20]. Gap-free arrangements, called perfect packings, of the infinite series of squares and boxes of side lengths {n t } n≥1 for a certain range of t have also been considered; see [3,[9][10][11]20].
A similar question, where the container is a square was answered in [2]. Here the authors proved that any set of squares can be packed into the unit square if (i) the total area of the squares is at most 5/9 and (ii) none of the squares has edge length larger than 1/2. They also proved that 5/9 is the best possible such value. We mention here that in their packing, the patterns used fulfill the guillotine pattern properties. Their packing is similar to the First Fit Decreasing Height (FFDH) heuristic of [4] designed for the two-dimensional strip packing problem, but they used it both horizontally and vertically.
Our results To the best of our knowledge, there are no asymptotic-type guarantees (upper bounds) to the problem of packing consecutive squares into a square. We fill this gap of the literature by delivering the first results of this nature, considering both guillotine-type packings and unrestricted axis-parallel packings.
We state our results in terms of packing squares into rectangles, from which packing into squares will be a corollary. To simplify formulas we introduce the notation A n := n(n+1)(2n+1) 6 and N := √ A n . Hence L B 0 = N , and no smaller square can contain a packing of the squares of sizes (= side lengths) 1, 2, . . . , n. We prove that a slightly bigger square admits a packing.
Theorem 1 There exists a constant c < 1 such that the square of size N + cn admits a guillotine-type packing of the squares of sizes 1, 2, . . . , n.
From the proof of the more general Theorem 4 in Sect. 2 it follows immediately that any c > 7/8 is a suitable choice for n ≥ n 0 (c). In the concluding section we shall indicate ways for improvements yielding a smaller constant. Even better bounds can be proved if the structure of cuts is not restricted, as shown in following result.
In Sect. 3 we prove this result in the following more general form.

Theorem 3 Let c be a fixed real number
then the squares of sizes 1, 2, . . . , n can be packed into an Certainly the O( √ n) term becomes superfluous for sufficiently large n ≥ n 0 ( , c).

Guillotine cutting
Here we prove Theorem 1 in the following more general form.
Theorem 4 If N 1 and N 2 are real numbers such that N 1 N 2 ≥ A n and N 1 ≤ N 2 , then an (N 1 + n) × (N 2 + cn) rectangle admits a packing of the squares 1, 2, . . . , n with guillotine cutting, where c is a suitable constant smaller than 1.
In the argument below, it is not our aim to optimize the value of c; we shall see that c = 3/4 surely works. Then, putting N 1 = N − n/8 + r (n) and N 2 = N + n/8 + r (n) we see that the condition N 1 N 2 ≥ A n = N 2 can be satisfied with a suitably chosen function r (n) = O( √ n), hence implying Theorem 1 for any c > 7/8 and large enough n.
The packing will be arranged in the decreasing order of the sizes of the squares, i.e. in the order n, n − 1, n − 2, . . . , 2, 1. The packing is done in several phases; the rough structure of Phase 1 and Phase 2 in cases where N 1 and N 2 are not very far from each other-say, N 1 > N 2 /8 or so-is shown in Fig. 1. In Phase 1 we deal with the squares of size i in the range n/2 − x < i ≤ n, for a relatively small x, as will be explained later. We consider a rectangle whose width is (N 1 + n) and height is (N 2 + cn), and take horizontal edge-to-edge cuts resulting in new rectangles R 1 , R 2 , . . . , R m , into which squares are placed side by side. Each R j will be filled to a width between N 1 and N 1 + n; we denote the height of R j by w j , which is the size of the largest square in R j . The starting height is w 1 = n. We pack the squares n, n − 1, . . . , w 2 + 1 into R 1 to reach width N 1 or a little more; that is, n i=w 2 +2 i < N 1 and n i=w 2 +1 i ≥ N 1 . The phase continues analogously: If R j−1 has been constructed and packed, let w j be the size of the largest square which has not yet been packed, and pack the squares w j , w j − 1, w j − 2, . . . , w j+1 + 1 into R j -which is an (N 1 + n) × w j rectangle-to reach width just N 1 or slightly beyond. This procedure terminates when also the rectangle R m containing the square n/2 + 1 is packed up to at least N 1 . This condition fixes the value of x, defined as a non-negative integer if n is even, or 1/2 plus a non-negative integer otherwise, such that the inequalities Hence, the number of squares packed in Phase 1 is n/2 + x, and the largest unpacked square has size n := n/2 − x.
The total height of this partial packing is H := w 1 + · · · + w m . Phase 2 deals with the rectangles n , n − 1, . . . , n /2 − x with some small x . If N 1 ≤ N 2 − H holds, then Phase 2 continues the procedure with horizontal edge-to-edge cuts exactly in the same way as we did in Phase 1, defining e.g. N 1 := N 1 and N 2 := N 2 − H + cn − cn . This leaves much space (namely, with width n) beyond N 1 horizontally and cn space beyond N 2 vertically, keeping N 2 ≥ N 1 . Otherwise, if N 1 > N 2 − H , we switch the roles of the two parameters so that N 1 := N 2 − H + cn − n and N 2 := N 1 + n − cn . In that case, Phase 2 creates vertical edge-to-edge cuts, placing the next squares on the top of each other and not leaving an empty vertical space more than n . In either case we provide at least a blank rectangle (N 1 + n ) × (N 2 + cn ) for the packing of the squares of sizes at most n . Hence, if we prove that N 1 N 2 ≥ A n = n i=1 i 2 holds, it will imply that all squares are properly packed after at most log 2 n phases, because there is always at least a halving of the number of items to pack.
Let us recall that in Phase 1 every R j (1 ≤ j ≤ m) is filled to width N 1 or beyond, but this property does not remain valid if we remove any one square from the contents of R j . We are going to apply the latter fact for the largest square in each rectangle and derive an upper bound on how large area remains blank in R 1 ∪ · · · ∪ R m within width N 1 . Choose any one j, let w = w j , and assume that exactly k + 1 squares are packed in R j . We know that There is no blank space above the square of size w, and for i = 1, . . . , k the blank area above the square of size w − i is i · (w − i). Hence, using that the sum of squares of the first k positive integers is A k , the total blank area in this rectangle is Summing for j = 1, . . . , m we see that the total blank area in R 1 ∪· · ·∪ R m containing the n − n largest squares is smaller than 1 2 (n − n )N 1 . The total area of squares packed in Phase 1 is A n − A n = n i=n/2−x+1 i 2 . Then the height packed so far is Hence N 2 − H > A n /N 1 − 1 2 n + 1 2 n . What remains is the following: -squares of sizes 1, 2, . . . , n , having total area A n , to be packed; -a rectangle for the packing, with side lengths at least N 1 + n and N 2 + cn .
Depending on whether or not the cutting direction has been switched from horizontal to vertical, we need to verify the following for a suitable value of c : Case (a) is implied by Eq. (1) immediately for any c ≥ 1/2 : Case (b) is not hard either. First apply Eq. (1) also here, to obtain The second term in the last line is positive. Taking into account that n ≤ n/2, it is also clear that (2c − 1)n ≥ n holds whenever c ≥ 3/4. Thus, the sum is at least A n for this choice of c. It is clear from the procedure that the structure is a guillotine cutting. This completes the proof.

Unrestricted packing
Here we prove Theorem 3-packing all squares of sizes between 1 and n into an (N 1 + n) × (N 2 + n + O( √ n)) rectangle-with a similar argument as in the proof of Theorem 1, using here a denser packing inside the subrectangles. Throughout the proof we assume that > 0 is a parameter independent of the input size, and also without loss of generality that N 1 , N 2 are shrunk to satisfy N 1 N 2 = A n . Furthermore, c 1 , c 2 , . . . denote absolute constants which are also independent of , while 1 and 2 will be very near to . The O( √ n) term, whose hidden constant depends on the parameters and c of Theorem 3 but on nothing else, will be adjusted at the end.
This procedure applies a two-phase recursion; we consider all squares of sizes n in the first phase and the squares of size i with 2 n i n in the second phase. Intuitively, the rectangles of the previous construction are put in pairs (R 2i−1 , R 2i ) for i = 1, 2, . . . , the rectangle of odd index is rotated with 180 • , and the gap is eliminated; we illustrate this in Fig. 2. It is also possible that the smallest square on the top hangs over the largest square at the bottom.
Originally the height of R 2i−1 ∪ R 2i is w 2i−1 + w 2i , but the size of the last square in R 2i−1 is only w 2i + 1. Hence the two rows of squares can be pushed towards each other by w 2i−1 − (w 2i + 1) because the decrease of square sizes in R 2i is faster than their increase in R 2i−1 . This operation reduces the blank area considerably. We denote by S i the slice of height 2w 2i + 1 derived from R 2i−1 ∪ R 2i in this way. For complete slices an even number of rectangles R j is needed; hence we fill horizontal rectangles R 1 , R 2 , . . . , R m up to N 1 or slightly beyond (as in the case of guillotine cuts) by packing the squares of sizes n, n − 1, . . . , n + 1 under the following conditions: The rectangle R m is packed to at least N 1 , m is even, n ≤ n, and A n ≤ 3 A n . We take the largest possible such n ; this determines the halting condition for Phase 1. In the computations below, the O( . ) terms will always mean functions where the 'hidden constants' may only be related to c, never to . First of all let us note that the assumptions N 1 N 2 = (n 3 ) and cN 2 ≤ N 1 ≤ N 2 imply that both N 1 and N 2 have A n /A n we see that all squares of size at least 1 n are packed in Phase 1. This follows from the fact that xn(xn+1)(2xn+1) > x 3 n(n+1)(2n+1) holds for all 0 < x < 1. Also, 1 ≤ , but − 1 is rather small, because n −n = O( 1 √ n). Indeed, we have N 1 = (n √ n), and the sizes of squares packed in R m−1 ∪ R m are ( n), therefore the number of squares in is valid, hence the requirement A n ≤ 3 A n yields that the difference between n and the size of the largest square in R m−1 -if the latter is smaller-has an upper bound proportional to 1/ 2 . (Otherwise we would have stopped with R m−2 rather than R m .) After the construction of horizontal slices in Phase 1, the procedure is continued in Phase 2 with vertical slices placed on the top of the horizontal slices. Before giving its numerical conditions, let us state and prove several properties. The first claim is width-independent. 1 • If the number of squares packed in R 2i is k + 1, then the blank area in S i is at most k j=1 j 2 .
Proof Denote the height of slice S i by 2w + 1; by construction we have w = w 2i . As one can observe, there is a blank unit square surrounded by the four squares w − 1, w, w + 1, w + 2; a blank rectangle of height 1 and width 4 surrounded by the squares w − 2, w − 1, w + 2, w + 3; and so on. Generally, for any ≥ 0, the width of the unit-high blank rectangle surrounded by the squares w − − 1, w − , w + + 1, w + + 2 is equal to More precisely, this is the distance between the bottom-left corner of the square w − − 1 and the top-left corner of the square w + + 2, in the case that the latter also appears in the slice. If the latter is not present, we can still use this formula as an upper bound. This implies the validity of 1 • .

• The number of squares packed in S i is O( 1 √ n) for every i, and the number of slices is O( √ n).
Proof Recall that both N 1 and N 2 have growth order (n √ n). Moreover, since every packed square has size n, the number of squares in any S i is between c 1 √ n and c 2 √ n. We have fewer than n squares, therefore the number of slices is at most c 3 √ n.

• The largest vertical gap between squares of R
Proof Let a i and b i be the size of the smallest square in R 2i and the largest square in R 2i−1 , respectively. Recall that a i n and b i = a i + O( 1 √ n). There are at most N 1 /a i +1 squares in R 2i and at least , the height of the largest gap can be estimated as

• The total height of the slices is at most
Proof The total area of packed squares is A n − A n = (1 − 3 1 )N 1 N 2 , moreover by 3 • the blank area is O( 1 3 N 1 √ n). Since the totally packed width is at least N 1 , the assertion follows.
We view the term O( 1 3 √ n) as an additional slice of that height packed on the top of an (N 1 + n) × (N 2 + n) rectangle. Then in Phase 2 the slices of vertical position have a blank rectangle ( 3 1 N 2 + n) × (N 1 + n), into which only the squares n , n − 1, . . . , n + 1 have to be packed, for some n (and a blank rectangle has to be left empty for n , n − 1, . . . , 1). Hence the slices can be completely packed up to at least 3 1 N 2 , based again on the principle shown in Fig. 2. Here we require that n ≤ n and A n ≤ 3 A n . We take the largest possible such n ; this determines the halting condition for Phase 2. Define 2 := 3 √ A n /A n , i.e. A n = 3 2 A n = ( 1 2 ) 3 A n . Note that n ≤ 2 n , hence n ≤ 1 2 n, but still 2 − 1 2 is rather small, and all squares larger than 1 2 n are already packed.
In this phase 1 • remains valid, and the following analogues of 2 • -3 • -4 • can be observed. Proof A slice is packed to 3 1 N 2 or slightly beyond, and all squares are larger than n ≈ 1 2 n, while the largest square is n ≤ 1 n. Therefore the number of squares in a slice is least ≈ 2 2 N 2 /n and at most ≈ 2 N 2 /n. Fewer than n squares are packed in this phase, hence the number of slices does not exceed ≈ 1 2 n 2

• The largest horizontal gap inside a vertical slice is O(1).
Proof Let again a i and b i denote the size of the smallest and the largest square in an arbitrarily chosen vertical slice. Now we have a i 2 n and b i = a i + O( √ n). Since the slice is packed to 3 1 N 2 , the gap can be estimated from above with This upper bound does not depend on . Consequently the blank area inside each vertical slice is O( 3 N 2 ).

• The total width of the vertical slices is at most
Proof The area of squares packed during Phase 2 is A n − A n = 3 Since the totally packed height is at least 3 1 N 2 , the assertion follows.
If is very small and n is not too large, it may be technically complicated to separate the O( 1 √ n) term from n. This situation can be handled by packing no vertical slices beyond O( 1 √ n), turning the rest to horizontal position and placing them on the top of the additional slice of Phase 1. The term O( 1 3 √ n) then swallows the current O( 1 √ n). After these two phases an ( 3 2 N 1 + n) × ( 3 1 N 2 + n) rectangle remains blank. Apart from an additional lower-order height, it is more than enough for the packing of the squares not larger than 1 2 n, by a repeated application of such alternating horizontal/vertical phases whose number is at most log 1/ n . For the necessary extra height, say h(n), we obtain the following recursion: This yields h(n) ≤ C ( , c) √ n for a suitable constant C ( , c).

Concluding remarks
We have proved that the squares of sizes 1, 2, . . . , n can be packed with guillotine-type cuts into a square of size √ 1 2 + 2 2 + · · · + n 2 + cn, where c < 1 is a constant. The calculation yielding c ≤ 7/8 offers the possibility of obtaining slightly better bounds, for example by applying the following ideas: -In Case (b), i.e. N 1 > N 2 − H in the proof of Theorem 4, the coefficient of the major term n N 1 is positive not only for c ≥ 3/4 but also for all c > 21/32, and for large n it dominates the lower-order negative term of (n 2 ). This improves the upper bound for guillotine-cuts. -Instead of N 1 + n on the horizontal side one may take N 1 + cn where c is not very small but smaller than 1. Although this does not guarantee complete packing to N 1 or beyond in the first few rectangles, the rectangles containing squares not larger than cn can be overpacked and so compensate for the loss in rectangles of small indices. This improves the bounds in both types of packings.
However, for the sake of keeping this note short and not very technical, we did not intend to decrease the upper bounds given in our theorems to the limits of these methods.