Smallest Enclosing Rectangle Revisited
Abstract
Given a set of points in the plane, and a parameter , we consider the problem of computing the minimum (perimeter or area) axisaligned rectangle enclosing points. We present the first near quadratic time algorithm for this problem, improving over the previous neartime algorithm by Kaplan et al. [KRS17]. We provide an almost matching conditional lower bound, under the assumption that convolution cannot be solved in truly subquadratic time. Furthermore, we present a new reduction (for either perimeter or area) that can make the time bound sensitive to , giving near time. We also present a near linear time approximation algorithm to the minimum area of the optimal rectangle containing points. In addition, we study related problems including the sided, arbitrarily oriented, weighted, and subset sum versions of the problem.
1 Introduction
Given a set of points in the plane, and a parameter , consider the problem of computing the smallest area/perimeter axisaligned rectangle that contains points of . (Unless stated otherwise, rectangles are axisaligned by default.) This problem and its variants have a long history. Eppstein and Erickson [EE94] studied an exhaustive number of variants of this problem for various shapes.
For the minimum perimeter variant, the first work on this problem seems to be Aggarwal et al. [AIKS91], who showed a brute force algorithm with running time . Recently, Kaplan et al. [KRS17] gave an algorithm with running time that works for both minimum perimeter and area.
Several works derived algorithms with running time sensitive to , the number of points in the shape. Aggarwal et al. [AIKS91] showed an algorithm for the minimum perimeter with running time . This was improved to by Eppstein and Erickson [EE94] or alternatively by Datta et al. [DLSS95]. Kaplan et al.’s algorithm [KRS17] for the insensitive case, coupled with these previous techniques [EE94, DLSS95], results in an running time, which is currently the state of the art.
Known techniques [EE94, DLSS95] reduce the problem to solving instances of size . These reductions work only for the perimeter case, not the area case – in particular, there are incorrect attributions in the literature to results on the minimum area rectangle – see the introduction of de Berg et al. [dBCC16] for details. De Berg et al. described an algorithm with running time for minimum area. Both de Berg et al. [dBCC16] and Kaplan et al. [KRS17] left as an open question whether there is a reduction from the minimumarea problem to about instances of size , where hides^{1}^{1}1We reserve the right, in the future, to use the to hide any other things we do not like. polynomial factors in and . Such a reduction would readily imply an improved algorithm.
Our results.
We revisit the above problems and provide significantly improved algorithms:

Exact smallest enclosing rectangle. In Section 2.1 we describe an algorithm for the minimum enclosing rectangle (either area or perimeter) with running time (see Theorem 2.2). It is based on a new divideandconquer approach, which is arguably simpler than Kaplan et al.’s algorithm. Known reductions mentioned above then lead to an time algorithm for computing the minimum perimeter rectangle.

sensitive running time for smallest area. In Section 2.2 we describe a reduction of the minimumarea problem to instances of size (see Theorem 2.8). Our reduction uses shallow cutting for 3sided rectangular ranges [JL11] (see Appendix A) and is conceptually simple.
Plugging this the aforementioned new time algorithm leads to time algorithm for computing the minimum area enclosing rectangle (see Corollary 2.9). Thus, our new result strictly improves upon both Kaplan et al.’s and de Berg et al.’s results for all , from constant to .
The smallest enclosing rectangle problem is amenable to sampling. Kaplan et al. used samples in an approximation algorithm, with running time , that computes a rectangle containing at least points of a prescribed perimeter, where is the maximum number of points in any such rectangle. Similarly, using relative approximations [HS11], de Berg et al. [dBCC16] showed an algorithm that computes, in time, a rectangle containing points, where is the maximum number of points in any rectangle of a prescribed area. The “dual” problem, of approximating the minimum area rectangle containing points seems harder, since sampling does not directly apply to it.

Approximating the area of the smallest enclosing rectangle. In Section 2.3, we present an approximation algorithm that computes, in expected time, a rectangle containing points of area , for a constant , where is the smallestarea of such a rectangle (see Theorem 2.13).
We next present a flotilla of related results:

sided smallest enclosing rectangle. In Section 3.1 we (slightly) speed up the exact algorithm for the sided rectangles case (i.e., rectangles that must have their bottom edge on the axis). The running time is , and is obtained using known results on the (min,+)convolution problem [BCD14, Wil14] (see Theorem 3.16).

Arbitrarily oriented smallest enclosing rectangle. In Section 3.2 we briefly consider the variant where the rectangle may not be axisaligned. We show that this problem can be solved in time, slightly improving a previous result of [DGN05] when is not too small.

Minimumweight enclosing rectangle. In Section 3.3 we show how to extend our time algorithm to the related problem of finding a minimumweight rectangle that contains points, for given weighted points in the plane (see Theorem 3.17).

Subset sum for enclosing rectangle. In Section 3.4, we study the problem of finding a rectangle that contains points and has a prescribed weight (or as close as one can get to it). The running time of the new algorithm is (see Theorem 3.19).

Conditional lower bound. In Section 3.5, we prove that our near quadratic algorithm for exact minimum (perimeter or area) enclosing rectangle is near optimal up to an arbitrarily small polynomial factor, under a “popular” conjecture that the (min,+)convolution problem cannot be solved in truly subquadratic time [CMWW17].
2 Smallest enclosing rectangle
2.1 An exact nearquadratic algorithm
Our time algorithm for minimum enclosing rectangles is based on divideandconquer. It has some similarity with an time divideandconquer algorithm by Barbay et al. [BCNP14] for a different problem (finding the minimumweight rectangle for weighted points in the plane, without any enclosing constraint), but the new algorithm requires more ingenuity.
We start with a semidynamic data structure for a 1D subproblem:
Lemma 2.1.
Given a set of points in 1D with marked points, and an integer , we can maintain an space data structure, with preprocessing time, that supports the following operations:

report the shortest interval containing points of in time;

delete a marked point in time;

unmark a marked point in time.
Proof:
Sort the points , and let he resulting order. Consider the (implicit) matrix . Formally, the entry is (we are interested only in the top right part of this matrix) – such an entry can be computed in time directly from the sorted point set. The optimal quantity of interest is the minimum on the th diagonal; that is, . When a marked point get deleted, this corresponds to deleting a row and a column of – the quantity of interest remains the minimum along the th diagonal. Such a deletion, as far as a specific entry of the top right of the matrix is concerned, either {enumerate*}
removes it,
keeps it in its place,
shift it one diagonal down as its moves left, or
keep it on the same diagonal as it shifts both up and left (see Figure 2.1).
In particular, any sequence of at most deletions of elements can shift an entry in the matrix at most diagonals down. This implies that we need to keep track only of the diagonals of this matrix. To do better, observe that if we track the elements of an original diagonal of interest, the deletions can fragment the diagonal into at most groups, where each group still appear as contiguous run of the original diagonal.
To this end, let a fragment of a diagonal be either {enumerate*}
a singleton entry that appears in a row or column of a marked point, or
a maximum contiguous portion of the diagonal which does not touch any singleton entries from (i). It is easy to verify that the th diagonal of the matrix at any given point in time is made out of a sequence of at most fragments, where each fragment is an original fragment of one of the diagonals in the range .
As such, instead of storing all the elements of a fragment, we only maintain the minimum entry of the fragment (together with the information of what pairs of points it corresponds to). After this compression, a diagonal of interest can be represented as a linked list of fragment summaries. In the preprocessing stage, the algorithm computes this representation for the to diagonals (using this representation). This requires space, and time.
A deletion of a marked point then corresponds to taking a contiguous block of linked fragments at the th list and moving it to list , doing this surgery for . The blocks being moved start and end in singleton entries that correspond to the deleted point. We also need to remove these two singleton elements, and merge the two adjacent fragment summaries that are no longer separated by a singleton. This surgery for all the lists of interest can be done in time (we omit the tedious but straightforward details).
A query corresponds to scanning the th diagonal and reporting the minimum value stored along it. An unmarking operation corresponds to merging two fragment summaries and the singleton separating them into a single fragment summary, and doing this for all the lists. Both operations clearly can be done in time.
Theorem 2.2.
Given a set of points in the plane and an integer , one can compute, in time, the smallestarea/perimeter axisaligned rectangle enclosing points.
Proof:
We do divideandconquer by coordinates. Given a set of points in the plane, and horizontal slabs and , each containing points of , we describe a recursive algorithm to find a smallest enclosing axisaligned rectangle containing , under the restriction that the top edge is inside and the bottom edge is inside . It is assumed that either is completely above , or . It is also assumed that all points above or below have already been deleted from . There can still be a large number of points in (recursion will lower but not necessarily ). We will not explicitly store the points in , but rather “summarize” the points in an space structure. Namely, we assume that the coordinates of are maintained in the 1D data structure of Lemma 2.1, where the marked points are the points in .
The algorithm proceeds as follows:

If , then report the answer by querying in time. Else:

Divide into two horizontal subslabs and , each containing points of . Likewise divide into and .

For each , recursively solve the problem for the slabs and ;^{2}^{2}2If , one of the four recursive calls is unnecessary. to prepare for the recursive call, make a copy of , delete the (marked) points in above or below , and unmark the remaining points in , as shown in Figure 2.2. The time needed for these deletions and unmarkings, and for copying , is (we emphasize that this bound is independent of ).
The running time satisfies the recurrence
with , which gives . Initially, is the entire plane, with ; the data structure can be preprocessed in time. Thus, the total running time is .
One can readily get an algorithm with sensitive running time for the perimeter case, by reducing the problem into instance of size . This reduction is well known [EE94, DLSS95] in this case – approximate the smallest enclosing disk containing points in time, partition the plane into a grid with side length proportional to the radius of this disk, and then solve the problem for each cluster (i.e., group of grid cells) that contains at least points of , using our above algorithm. We thus get the following.
Corollary 2.3.
Given a set of points in the plane and an integer , one can compute, in time, the smallestperimeter axisaligned rectangle enclosing points of .
The term can be eliminated in the word RAM model, using a randomized lineartime algorithm for approximate smallest enclosing disk [HM05] (which requires integer division and hashing).
A similar reduction for the minimumarea case is more challenging, and was left as an open problem in previous work [KRS17]. The difficulty arises because the optimalarea rectangle may be long and thin, with side length potentially much bigger than the radius of the minimum enclosing disk. Nonetheless, we show that such a reduction is possible (with an extra logarithmic factor) in the next subsection.
2.2 sensitive running time for smallest area
Our starting point is a shallow cutting lemma for 3sided ranges [JL11], which we describe in detail in Appendix A for the sake of completeness. (It can be viewed as an orthogonal variant of Matoušek’s shallow cutting lemma for halfspaces [Mat92].)
Lemma 2.4 ([Jl11]).
Given a set of points in the plane, lying above a horizontal line , and a parameter , one can compute a family of at most subsets of , each of size at most . The collection of sets can be computed in time if the coordinates have been presorted. For any axisaligned rectangle with its bottom edge lying on , that contains less than points of , we have for some .
Definition 2.5.
Let be the set of all axisaligned rectangles in the plane. A scoring function is a function , with the following properties:

Translation invariant: , we have .

Monotonicity: , such that , we have that .
Functions that satisfy the above definition include area, perimeter, diameter, and enclosing radius of a rectangle.
For a set , let be the reflection of through the axis. Similarly, let be the folding of through the axis.
Lemma 2.6.
Given a set of points in the plane, a parameter , and a scoring function , let be the minimum score axisaligned rectangle that contains points of , and intersects the axis. Then, one can compute a family of subsets of , such that (i) each set of is of size , and (ii) , for some .
Proof:
Let be the “folding” of over the axis, and let be the cover of by sets of size , as computed by Lemma 2.4 for rectangles containing at most points. Let be the corresponding family of sets for . We claim that has the desired property.
Let be the folding of , and let . Observe that because of the translation invariance of , and monotonicity of .
If then one can shrink it so that it contains only points of , but this would imply that is not the minimum, a contradiction. The case that leads to a similar contradiction. We conclude that contains at most points of . Implying that contains at most points of . As such, there is a set that contains . Now, let be the corresponding set in to . Since , it follows that , as desired.
Lemma 2.7.
Given a set of points in the plane, a parameter , and a scoring function , let be the minimum score rectangle that contains points of . One can compute, in time, a family of subsets of , such that (i) each subset of is of size , and (ii) , for some .
Proof:
Find a horizontal line that splits evenly, and compute the family of Lemma 2.6. Now recurse on the points above and the points below . The recursion bottoms out when the number of points is . The correctness is by now standard – as soon as a recursive call picks a line that stabs the optimal rectangle, the family generated for this line contains the desired set. The coordinates need to be presorted just once at the beginning.
Theorem 2.8.
Let be a set of points in the plane, be a parameter, be a scoring function for rectangles, and let alg be an algorithm the computes, in time, the axisaligned rectangle containing points in a set of points that minimizes . Then one can compute the rectangle containing points of that minimizes , in time
Proof:
Compute the family of sets using Lemma 2.7, and then apply alg to each set in this family.
Combining Theorem 2.2 with Theorem 2.8 gives the following.
Corollary 2.9.
Given a set of points in the plane and an integer , one can compute, in time, the smallestarea axisaligned rectangle enclosing points of .
For the case when is very small (i.e., finding the smallest enclosing axisaligned rectangle with outliers), there is an easy reduction (for both perimeter and area) yielding time [SK98, ABC09], by keeping the leftmost/rightmost/topmost/bottommost points. Immediately from Theorem 2.2, we get running time.
2.3 An approximation algorithm for smallest area
In this subsection, we give an efficient approximation algorithm for the smallestarea enclosing rectangle problem. The smallest perimeter case is straightforward to approximate, by grid rounding, but the area case is tougher, again because the optimal rectangle may be long and thin.
Definition 2.10.
A laminar family of 3sided rectangles is a collection of axisaligned rectangles with the bottom edges lying on the axis, such that for every pair of rectangles and in , one of the following is true:

, or

and , or

and .
Standard range trees can answer orthogonal range counting queries (counting the number of points inside rectangular ranges) in logarithmic time per query (this has been improved to in the offline setting by Chan and Pătraşcu [CP10]). The following lemma shows how to achieve constant time per query in the offline laminar special case, which will be useful later in our approximation algorithm.
Lemma 2.11.
Let be a set of points, and let be a laminar family of 3sided rectangles in the plane. Suppose that we are given a designated point on the top edge of each rectangle in , and the  and coordinates of all the designated points and all the points of have been presorted. Then we can count, for each rectangle , the number of points of inside the rectangle, in total time.
Proof:
We describe a sweep algorithm, with a horizontal sweep line moving downward. Let denote the set of coordinates of all points of and all designated points of the rectangles of . Consider the union of over all ; it can be expressed as a union of disjoint intervals. Let be the projection of these disjoint intervals. Store the following collection of disjoint sets in a unionfind data structure [Tar75]: for each interval , define the set , and for each not covered by , define the singleton set . Create a linked list containing these sets in ordered by . For each set in , we store a count of the number of points of below with coordinates inside the set.
Suppose that the sweep line hits the top edge of a rectangle with projection . By definition of a laminar family, any interval in that intersects must be contained in . We find the set in that contains the coordinate of the designated point of . From this set, we walk through the list in both directions to find all sets contained in , and replace these sets with their union in and . The count for the new set is the sum of the counts of the old sets; this also gives the output count for the rectangle .
Next, suppose that the sweep line hits a point . We find the set in that contains the coordinate of , and decrement its count. (For example, if the set is a singleton, its count changes from 1 to 0.)
The entire sweep performs union and find operations. Gabow and Tarjan [GT85] gave a lineartime unionfind algorithm for the special case where the “union tree” is known in advance; their algorithm is applicable, since the union tree here is just a path of the elements ordered by .
We first solve the approximate decision problem:
Lemma 2.12.
Given a set of points in the plane, a value , and parameters and , one can either compute a enclosing axisaligned rectangle such that , or conclude that the smallestarea enclosing axisaligned rectangle has area greater than . The running time of the algorithm is .
Proof:
It is sufficient to solve the problem for the case where the rectangle must intersect a horizontal line in time, assuming that the  and coordinates of the given points have been presorted. Then standard divideandconquer by coordinates gives an time algorithm for the general problem. Presorting needs to be done only once at the beginning.
Without loss of generality, assume that is the axis. Suppose there exists a rectangle intersecting that contains at least points and has area at most . By symmetry, we may assume that has greater area above than below, and that the top edge passes through some input point . Then the height of is between and , and the width is at most .
Without loss of generality, assume that all coordinates are in . Define a onedimensional quadtree interval (also known as a dyadic interval) to be an interval of the form . It is known that every interval of length is contained in a quadtree interval of length after shifting the interval by one of two possible values (this is a special case of a shifting lemma for dimensional quadtrees [Ber93, Cha98]). Thus, suppose that is contained in the interval , where the length is equal to the smallest power of 2 greater than , for some constant . (Note that is a nondecreasing function of .) Without loss of generality, assume that for an integer . Define a family of canonical rectangles of the form
over all possible indices such that .
By rounding, is contained in a canonical rectangle with height at most and width at most
and thus area at most . So, it suffices to count the number of points inside each canonical rectangle and return the smallest area among those rectangles containing at least points.
To speed up range counting, observe that for canonical rectangles with the same , the same , and the same value for , the portion of the rectangles above (resp. below) forms a laminar family. This is because: (i) in the projections, if a pair of intervals intersects, one interval must be contained in the other; (ii) as the height of the 3sided rectangle increases, increases, and so can only increase (or stay the same), and so the width of the rectangle can only decrease (or stay the same). Thus, we can apply Lemma 2.11 to compute the counts of the points inside each rectangle, for all canonical rectangles with a fixed and , in time (for each canonical rectangle, we can use a point on the top edge, and a corresponding point on the bottom edge, as the designated points). The number of choices for and is .
Theorem 2.13.
Given a set of points in the plane, and parameters and , one can compute a enclosing rectangle such that , where is the area of the smallest axisaligned rectangle containing points of . The expected running time of the algorithm is .
Proof:
We can use known techniques for reducing optimization problems to decision problems. We give a selfcontained description of one approach based on Chan’s randomized technique [Cha99].
Let be a sufficiently large constant. Divide the plane into columns (vertical slabs) each containing points. Similarly divide the plane into rows (horizontal slabs) each containing points. These steps take linear time by invoking a selection algorithm times. For each quadruple where and are columns (with left of or ) and and are rows (with below or ), consider the subproblem of finding the smallestarea rectangle containing points of , subject to the extra constraints that the left edge of the rectangle lies in , the right edge lies in , the bottom edge lies in , and the top edge lies in . To solve this subproblem, it suffices to consider the at most points in . To ensure that the extra constraints are satisfied, we add copies of the four intersection points formed by the right boundary of , the left boundary of , the top boundary of , and the bottom boundary of ; and we add to . (Straightforward modifications can be made in the special case when or .) Let be the resulting point set of size at most points, and be the resulting value of . We thus have
To compute an approximation to the minimum, we consider the at most quadruples in random order and keep track of an approximate minimum with the invariant that after the th iteration. Let be such that ; note that . At the th iteration, we run the approximate decision procedure for twice, at values and , which allows us to conclude one of the following:

. In this case, we can continue to the next iteration and the invariant is maintained.

. In this case, we reset to and the invariant is maintained.

. In this case, we recursively compute an approximation to , satisfying . We reset to and the invariant is maintained.
We land in the third case only if is the smallest among the values , which happens with probability at most . Thus, the expected number of recursive calls is bounded by the th Harmonic number . The expected running time satisfies the recurrence
which gives when , for example.
3 Extensions
3.1 3sided smallest enclosing rectangle
In this subsection, we give a slightly faster algorithm for the 3sided variant of the problem, finding the smallestarea/perimeter rectangle enclosing points, under the restriction that the bottom edge lies on the axis. The improvement uses the latest result on the (min,+)convolution problem, and is interesting in view of a reduction in Section 3.5 in the reverse direction, establishing essentially an equivalence of the 3sided problem to (min,+)convolution.
Problem 3.14.
(min,+)Convolution. Given real numbers , compute for all .
Let be the time complexity of the (min,+)convolution problem. As observed by Bremner et al. [BCD14], the problem can be reduced to (min,+)matrix multiplication, and using the current best result by Williams [Wil14] (derandomized by Chan and Williams [CW16]), . We use (min,+)convolution to speed up the preprocessing time of the 1D data structure from Section 2.1.
Lemma 3.15.
The preprocessing time in Lemma 2.1 can be reduced to .
Proof:
Divide the matrix vertically into submatrices each of dimension . For each submatrix , we consider the portions of the diagonals that are within – each such portion will be called a chunk. We precompute the minimum of the entries in each chunk. For a fixed , this is equivalent to computing for all . Notice that after some massaging of the sequence (negating, reversing, and padding), this computation can be reduced to (min,+)convolution over elements, and can thus be done in time. The total time over all is .
Recall that in the preprocessing algorithm in Lemma 2.1, we need to compute the minimum of each fragment in the diagonals. Each fragment can be decomposed into some number of disjoint chunks plus extra elements. Over all diagonals, there are fragments and chunks in total. Thus, we can compute the minima of all fragments in time, after the above precomputation of the minima of all chunks.
Theorem 3.16.
Given a set of points in the plane and integer , one can compute, in time, the smallestarea/perimeter axisaligned rectangle enclosing points of , under the restriction that the bottom edge lies on the axis.
Proof:
Divide the plane into horizontal slabs each containing points, for some parameter to be set later.
Take such a slab . We solve the subproblem of finding a smallest enclosing axisaligned rectangle under the restriction that the top edge is in and the bottom edge is on the axis. To this end, we first delete all points above or below the axis. We build the 1D data structure in the lemma for the coordinates of the surviving points, where the marked points are the points in . The preprocessing time is . Then for each point , we can compute a smallest enclosing axisaligned rectangle where the top edge has ’s coordinate and bottom edge is on the axis, by making a copy of , deleting all points in above , and querying . The time needed for the deletions, and for copying , is . The total time over all is .
We return the minimum (by area or perimeter) of all the rectangles found. The overall running time over all slabs is
With , we can set , for example, and obtain the final time bound .
For sensitive bounds, we can apply the shallow cutting technique from Section 2.2 (which is easier for 3sided rectangles) and obtain an time bound.
3.2 Arbitrarily oriented smallest enclosing rectangle
We briefly consider the problem of computing a smallestarea/perimeter arbitrarily oriented rectangle (not necessarily axisaligned) enclosing points. The optimal rectangle is defined by 5 points, with one edge containing 2 points and . Given a fixed choice of and , we can use a rotation and translation to make lie on the axis and thereby obtain a 3sided axisaligned rectangle problem, which can be solved in time. Exhaustively trying all pairs then gives total time.
3.3 Minimumweight enclosing rectangle
Our time algorithm can be adapted to solve the following related problem. (Without the constraint, the problem has an time algorithm [BCNP14].)
Theorem 3.17.
Given a set of points in the plane each with a real weight, and an integer , one can compute, in time, the axisaligned rectangle enclosing points minimizing the total weight of the points inside.
Proof:
We follow the same approach as in Section 2.1, with the following differences in the data structure of Lemma 2.1. For every fragment we maintain the minimum weight solution. Using prefix sums, the entry in the matrix contains the total weight of the elements from to . As before, we break the diagonals of entry into fragments, where each fragment summary maintains the minimum weight encountered.
A deletion of a marked point of weight would result is an insertion of a fixup entry, of value into a linked list of a diagonal where appeared as a singleton (when crossing a column of ), and a fixup entry of value when encountering the row column of . The real value of a fragment is the value stored in the fragment plus the total sum of the fixups appearing before it in the linked list of its diagonal. As such, during query the real value can be computed in time overall, as this list is being scanned. When we merge two adjacent fragments separated by a singleton, we should increase the later fragment by the fixup value at the singleton before taking the minimum. Clearly, all the operations can be implemented in time.
Now, we can use the divideandconquer algorithm in the proof of Theorem 2.2 with no change.
As an application, we can solve the following problem: given points in the plane each colored red or blue, and an integer , find an axisaligned rectangle enclosing exactly points minimizing the number of red points inside. This is a special case of the problem in the above theorem, where the red points have weight 1 and blue points have weight 0, and can thus be solved in time.
Similarly, we can solve for other variants of the red/blue problem, for example, finding a enclosing rectangle maximizing (or minimizing) the number of red points, or finding a enclosing rectangle with exactly a given number of red points. (For the latter, the following observation allows us to reduce the 1D subproblem to querying for the maximum and minimum: given a set of red/blue points in 1D and a value , let denote the set of all possible values for which there exists an interval containing points of and exactly red points; then forms a contiguous range of integers, and thus contains all numbers between and .)
3.4 Subset sum for enclosing rectangle
A more challenging variant of the weighted problem is to find a rectangle enclosing exactly points with total weight exactly (similar to subset sum), or more generally, find an axisaligned rectangle enclosing exactly points with total weight closest to .
We use a different approach, using a 1D data structure that is static but can “plan for” a small number of deletions.
Lemma 3.18.
Given a set of points in 1D and integers and , we can build a static data structure, with preprocessing time, that supports the following type of queries in time: for any subset of at most points and any weight , find an interval containing points of with weight closest to .
Proof:
As in the proof of Lemma 2.1, we sort and consider the (implicit) matrix . For each , we store the elements in the th diagonal in a data structure supporting 1D range predecessor/successor queries – i.e., finding the predecessor/successor to any value among the elements in any contiguous sublist of a given list – in time, after preprocessing time. (See [Zho16] for the latest result on the range successor problem; for simplicity, we will ignore improvements in the logarithmic factors here.) The total preprocessing time for all diagonals is .
To answer a query, we imagine deleting the columns and rows associated with the elements in , from the matrix . We want to search for in the th diagonal in the modified matrix. This diagonal corresponds to fragments from the diagonals in the original matrix. Namely, as we trace the diagonal in the original matrix from left to right, whenever we hit a deleted column, we move to the diagonal one unit up, and whenever we hit a deleted row, we move the diagonal one unit down. We can search for in each fragment by a range predecessor/successor query in a diagonal in time. We return the closest point found. The total query time is .
Theorem 3.19.
Given points in the plane each with a real weight, and given a real number and an integer , one can compute, in time, an axisaligned rectangle enclosing exactly points with total weight closest to .
Proof:
Divide the plane into horizontal slabs each containing points, for some parameter to be set later.
Take a pair of horizontal slabs and . We solve the subproblem of finding a enclosing axisaligned rectangle with weight closest to , under the restriction that the top edge is in and the bottom edge is in . To this end, we first remove all points strictly above and strictly below . We build the 1D data structure in Lemma 3.18 for (the coordinates of) the surviving points in time. Then for each pair of points and , we can search for a enclosing axisaligned rectangle with weight closest to , under the restriction that the top edge has ’s coordinate and the bottom edge has ’s coordinate, by performing a query to the 1D data structure in time for the subset of (the coordinates of) the points above in and the points below in . The total query time over all pairs of points is .
We return the closest answer found. The total running time over all pairs of slabs is
We set .
We can further improve the running time for small :
Theorem 3.20.
Given points in the plane each with a real weight, and given a real number and an integer , one can compute, in time, an axisaligned rectangle enclosing exactly points with total weight closest to .
Proof:
We first consider the variant of the problem where the rectangle is constrained to intersect a fixed vertical line . Here, we can follow essentially the same algorithm as in Theorem 3.19 (with minor modifications to the data structure in Lemma 3.18), but when considering the subproblem for the two slabs and , we can further remove more irrelevant points: among the points strictly between and , it suffices to keep only the points immediately to the left of and the points immediately to the right of . It may be too costly to compute these points from scratch, but given such points for for the predecessor slab of , we can generate the new points for , by invoking a selection algorithm on elements in time. The number of points in the subproblem is now reduced to . As a consequence, the overall running time becomes
We set . This gives an time algorithm for the restricted problem with the vertical line .
We can solve the original problem now via standard divideandconquer by coordinates, with running time given by the recurrence , which solves to .
As an application, we can solve the following problem: given colored points in the plane with different colors, and integers , with , find an axisaligned rectangle enclosing exactly points of the th color. The problem was proposed by Barba et al. [BDF13], who gave an time algorithm. (It may be viewed as a geometric variant of the jumbled or histogram indexing problem for strings [CL15].) It is a special case of the problem from Theorem 3.19: we can give points with color a weight of for a sufficiently large , e.g., , and set the target to . Since weights require bits, each addition has cost, and so the running time becomes . The weights can be reduced to bits by randomized hashing (for example, by randomly selecting from and working with numbers modulo for an bit prime ), since there are only polynomially (i.e., ) many combinatorially different rectangles. This way, the running time can be reduced to – this improves Barba et al.’s result.
3.5 Conditional lower bounds
We can prove that the smallestperimeter enclosing axisaligned rectangle problem do not have truly subquadratic () algorithms, under the conjecture that (min,+)convolution does not have a truly subquadratic algorithm. Our proof holds for the 3sided version of the problem, which complements nicely with our upper bound in Section 3.1 using (min,+)convolution.
We describe a reduction from the following decision problem, which Cygan et al. [CMWW17] showed does not have a truly subquadratic algorithm under the (min,+)convolution conjecture.
Problem 3.21.
(min,+)Convolution Decision. Given real numbers and , decide whether
Theorem 3.22.
If there is a time algorithm for computing the smallestperimeter/area axisaligned rectangle enclosing points for a given set of points in the plane and a given number (with or without the constraint that the bottom edge lies on the axis), then there is an time algorithm for Problem 3.21.
Proof:
Consider an instance of Problem 3.21. Without loss of generality, assume . We create an instance of the minimumperimeter enclosing rectangle problem with points
plus extra copies of and extra copies of , and , where is a sufficiently large number, e.g., .
The optimal perimeter is
which is at least iff for every .
For minimum area, the reduction is similar, except that we replace with . The optimal area is
which is at least 1 iff for every .
A similar reduction holds for the minimumweight enclosing rectangle problem from Theorem 3.17:
Theorem 3.23.
If there is a time algorithm for computing the minimumweight axisaligned rectangle enclosing points for a given set of weighted points in the plane and number (with or without the constraint that the bottom edge lies on the axis), then there is an time algorithm for Problem 3.21.
Proof:
The reduction is similar. Assume . We create an instance of the minimumweight enclosing rectangle problem with weighted points
plus extra copies of the points and , and , where is a sufficiently large number, e.g., . The third coordinate after the semicolon of each point denotes its weight. (And .)
The minimum weight over all rectangles with points is equal to
which is nonnegative iff for every .
A nearquadratic conditional lower bound for the minimumweight rectangle problem without the constraint was given by Backurs et al. [BDT16] (under a different “popular” conjecture about the complexity of maximumweight clique).
We can similarly prove that the subsetsum variant of the enclosing rectangle problem from Theorem 3.19 (or its 3sided variant) does not have truly subquadratic algorithms, under the conjecture that the convolution3SUM problem (given real numbers , decide whether