Maximum rectilinear convex subsets
Hernán González-Aguilar, David Orden, Pablo Pérez-Lantero, David Rappaport, Carlos Seara, Javier Tejel, Jorge Urrutia
MMaximum rectilinear convex subsets
Hern´an Gonz´alez-Aguilar ∗ , David Orden † , Pablo P´erez-Lantero ‡ , DavidRappaport § , Carlos Seara ¶ , Javier Tejel (cid:107) , and Jorge Urrutia ∗∗ Facultad de Ciencias, Universidad Aut´onoma de San Luis Potos´ı, Mexico. Departamento de F´ısica y Matem´aticas, Universidad de Alcal´a, Spain. Departamento de Matem´atica y Ciencia de la Computaci´on, USACH, Chile. School of Computing, Queen’s University, Canada. Departament de Matem`atiques, Universitat Polit`ecnica de Catalunya, Spain. Departamento de M´etodos Estad´ısticos, IUMA, Universidad de Zaragoza, Spain. Instituto de Matem´aticas, Universidad Nacional Aut´onoma de M´exico, Mexico.
Abstract
Let P be a set of n points in the plane. We consider a variation of the classical Erd˝os-Szekeres problem, presenting efficient algorithms with O ( n ) running time and O ( n ) spacecomplexity that compute: (1) A subset S of P such that the boundary of the rectilinearconvex hull of S has the maximum number of points from P , (2) a subset S of P such thatthe boundary of the rectilinear convex hull of S has the maximum number of points from P and its interior contains no element of P , (3) a subset S of P such that the rectilinear convexhull of S has maximum area and its interior contains no element of P , and (4) when eachpoint of P is assigned a weight, positive or negative, a subset S of P that maximizes thetotal weight of the points in the rectilinear convex hull of S . Keywords:
Erd˝os-Szekeres problems, convex subsets, optimization, orthoconvexity, rectilinearconvex hull.
Let P be a point set in general position in the plane. A subset S of P with k elements is called a convex k -gon if the elements of S are the vertices of a convex polygon, and it is called a convex k -hole of P if the interior of the convex hull of S contains no element of P . The study of convex ∗ Email: [email protected] † Research supported by project MTM2017-83750-P of the Spanish Ministry of Science (AEI/FEDER, UE).Email: [email protected] ‡ Research supported by project CONICYT FONDECYT/Regular 1160543 (Chile). Email:[email protected] § Research supported by NSERC of Canada Discovery Grant RGPIN/06662-2015. Email: [email protected] ¶ Research supported by projects MTM2015-63791-R MINECO/FEDER and Gen. Cat. DGR 2017SGR1640.Email: [email protected] (cid:107)
Research supported by projects MTM2015-63791-R MINECO/FEDER and Gobierno de Arag´on E41-17R.Email: [email protected] ∗∗ Research supported by PAPIIT grant IN102117 from UNAM. Email: [email protected] work has received funding from the European Union’s Horizon 2020 researchand innovation programme under the Marie Sk(cid:32)lodowska-Curie grant agreement No734922. a r X i v : . [ c s . C G ] J u l -gons and convex k -holes of point sets started in a seminal paper by Erd˝os and Szekeres [9] in1935. Since then, numerous papers about both the combinatorial and the algorithmic aspects ofconvex k -gons and convex k -holes have been published. The reader can consult the two surveypapers about so-called Erd˝os-Szekeres type problems [7, 11].There are recent papers studying the existence and number of convex k -gons and convex k -holes for finite point sets in the plane [1, 2, 3]. Papers dealing with the algorithmic complexityof finding largest convex k -gons and convex k -holes are, respectively, Chv´atal and Kincsek [8]and Avis and Rappaport [5], which solve these problems in O ( n ) time.Erd˝os-Szekeres type problems have also been studied for colored point sets. Let P be a pointset such that each of its elements is assigned a color, say red or blue. Bautista-Santiago et al. [6]studied the problem of finding a monochromatic subset S of P of maximum cardinality suchthat all of the elements of P contained in the convex hull of S have the same color. As ageneralization, they also studied the problem in which each element of P has assigned a (positiveor negative) weight. In this case, the goal is to find a subset S of P that maximizes the totalweight of the points of P contained in the convex hull of S . Each of these problems was solvedin O ( n ) time and O ( n ) space. Further, their algorithm can easily be adapted to find a subset S of P such that the convex hull of S is empty and of maximum area in O ( n ) time and O ( n )space.In this paper, we study Erd˝os-Szekeres type problems under a variation of convexity knownas rectilinear convexity , or orthoconvexity : Let P = { p , . . . , p n } be a set of n points in theplane in general position. A quadrant of the plane is the intersection of two open half-planeswhose supporting lines are parallel to the x - and y -axes, respectively. We say that a quadrant Q is P - free if it does not contain any point of P . The rectilinear convex hull of P , denoted as RCH ( P ), initially defined by Ottmann et al. [12], is defined as: RCH ( P ) = R − (cid:91) Q is P - free Q. The rectilinear convex hull of a point set might be a simply connected set, yielding anintuitive and appealing structure (see Figure 1a). However, in other cases the rectilinear convexhull can have several connected components (see Figure 1b), some of which might be singlepoints which we call pinched points. The size of RCH ( P ) is the number of elements of P onthe boundary of RCH ( P ). The sizes of the rectilinear convex hulls in Figures 1a and 1b are,respectively, thirteen and twelve.Alegr´ıa-Galicia et al. [4] gave an optimal Θ( n log n )-time and O ( n )-space algorithm to com-pute the orientation of the coordinate axes such that the rectilinear convex hull of a set P of n points in the plane has minimum area. The reader can refer to the literature for other resultsrelated to rectilinear convexity [4, 10, 14]. In this paper, we present efficient algorithms for thefollowing geometric optimization problems: MaxRCH : Given a set P of n points in the plane, find a subset S ⊆ P such that the size of RCH ( S ) is maximized. MaxEmptyRCH : Given a set P of n points in the plane, find a subset S ⊆ P such that theinterior of RCH ( S ) contains no point of P and the size of RCH ( S ) is maximized. MaxAreaRCH : Given a set P of n points in the plane, find a subset S ⊆ P such that the interiorof RCH ( S ) contains no point of P and the area of RCH ( S ) is maximized. MaxWeightRCH : Given a set P of n points in the plane, such that each p ∈ P is assigned a(positive or negative) weight w ( p ), find a subset S ⊆ P that maximizes (cid:80) p ∈ P ∩ RCH ( S ) w ( p ).In Section 3, we give an O ( n )-time O ( n )-space algorithm to solve the MaxRCH problem.Then, in Section 4 we show how to adapt this algorithm to solve the other three problems,each in O ( n ) time and O ( n ) space. The complexities of our algorithms are the same as the2 b cd − staircase − staircase − staircase − staircase (a) a = d b cu (b) Figure 1: (a) A point set with a connected rectilinear convex hull. (b) A point set whose rectilinearconvex hull is disconnected, two of its components are pinched points. complexities of the best-known algorithms to solve these problems with the usual definition ofconvexity.
For the sake of simplicity, we assume that all point sets P considered in this paper are in general position , which means that no two points of P share the same x - or y -coordinate. Usinga O ( n log n )-time preprocessing step, we can also assume when necessary that the points of apoint set P are ordered by x -coordinate or y -coordinate. Given a point set P in the plane, wewill use a , b , c , and d to denote the leftmost, bottommost, rightmost, and topmost points of P ,respectively, unless otherwise stated. Note that a , b , c , and d are not necessarily different. InFigure 1b, we have a = d . p = v q = v k v v k − (a) p Q ( p ) Q ( p ) Q ( p ) Q ( p ) (b) M ( P ) (c) Figure 2: (a) A 1-staircase. (b) The definition of the sets Q i ( p ). (c) A 7-point set P and its M ( P ).The vertices of the boundary of M ( P ) in P are the 1-extremal points of P . The thick polygonal line isthe 1-staircase associated with P . Given a point p of the plane, let p x and p y denote the x - and y -coordinates of p , respectively.For p, q ∈ R , p (cid:54) = q , we write p ≺ q to denote that p x < q x and p y < q y , and p ≺ (cid:48) q to denotethat p x < q x and p y > q y . Let p, q ∈ R , and consider a set S = { v , . . . , v k } of k pointssuch that v = p , v k = q , and v i ≺ (cid:48) v i +1 for i = 1 , , . . . , k −
1. A 1 -staircase joining p to q is an orthogonal polygonal chain, such that two consecutive elements of S are joined by anelbow consisting of a horizontal segment followed by a vertical segment. For an illustration, seeFigure 2a. A 3 -staircase joining p to q is defined in a similar way, but using elbows whose first3egment is vertical. Analogously, we define 2- and 4-staircases, except that we require v i ≺ v i +1 .The first segment is vertical in the 2-staircase and horizontal in the 4-staircase. Points of S arecalled the vertices of the staircase.Any point p in the plane defines four open axis-aligned quadrants Q i ( p ), i = 1 , , , Q ( p ) = { q ∈ R | p ≺ q } , Q ( p ) = { q ∈ R | q ≺ (cid:48) p } , Q ( p ) = { q ∈ R | q ≺ p } , and Q ( p ) = { q ∈ R | p ≺ (cid:48) q } . Given a point set P in the plane,for i = 1 , , ,
4, let M i ( P ) = (cid:91) p ∈ P Q i ( p ) , where Q i ( p ) denotes the closure of Q i ( p ). The elements of P that belong to the boundaryof M i ( P ), are called the (rectilinear) i - extremal points of P (see Figure 2c). Note that the i -extremal points of P are the vertices of a i -staircase connecting all of them. This i -staircase,that we call the i -staircase associated with P , is the part of the boundary of M i ( P ) that connectsall the i -extremal points of P (see Figure 2c). For every J ⊆ { , , , } , we say that p ∈ P is J -extremal if p is j -extremal for every j ∈ J . The rectilinear convex hull of P is the set RCH ( P ) = (cid:92) i =1 , , , M i ( P ) , see Figure 1. The boundary of RCH ( P ) is (a part of) the union of the 1-, 2-, 3- and 4-staircasesassociated with P . Observe that the endpoints of these four staircases are a, b, c and d , a is { , } -extremal, b is { , } -extremal, c is { , } -extremal, and d is { , } -extremal. In Figure 1b,as a = d , then a is { , , } -extremal and the 4-staircase associated with P consists of only point a . Observe that RCH ( P ) is disconnected when either the intersection of the complements R \ M ( P ) and R \ M ( P ) is not empty, as shown in Figure 1b, or the intersection of thecomplements R \ M ( P ) and R \ M ( P ) is not empty. In other words, when either the 1- and3-staircases associated with P cross or the 2- and 4-staircases associated with P cross. Definition 2.1. A pinched point u of RCH ( P ) occurs when u is either { , } -extremal, asshown in Figure 1b, or { , } -extremal. Definition 2.2.
The size of RCH ( P ) is the number of points of P which are i -extremal for atleast one i ∈ { , , , } . From the definition of the staircases for P , the following observation is straightforward. Observation 2.3.
Assume that the concatenation of the four i -staircases associated with P istraversed counter-clockwise. For two consecutive i -extremal points p and p (cid:48) , Q i +2 ( o ) containsno element of P , where i + 2 is taken modulo and o = ( p (cid:48) x , p y ) for i = 1 , or o = ( p x , p (cid:48) y ) for i = 2 , . Given two points u (cid:54) = v in the plane, let B ( u, v ) denote the smallest open axis-alignedrectangle containing u and v , and let P ( u, v ) = P ∩ B ( u, v ). Note that u and v are two opposedcorners of B ( u, v ). If u = v , then we define B ( u, u ) as point u . Definition 2.4.
We say that
RCH ( P ) is vertically separable if rectangles B ( a, d ) and B ( b, c ) are separated by a vertical line. The two examples shown in Figure 1 are vertically separable. Given a point set S , and a horizontal line (cid:96) , let S (cid:48) be the image of S under a reflectionaround (cid:96) . The following lemma is key for our algorithms: The notation RH ( P ) is also used for the rectilinear convex hull [4]. emma 2.5. For all S ⊆ P , | S | ≥ , either RCH ( S ) or RCH ( S (cid:48) ) is vertically separable.Proof. Note that d x < b x is necessary and sufficient for vertical separability of B ( a, d ) and B ( b, c ), that is, RCH ( S ) is vertically separable. Suppose then that b x < d x , and let (cid:96) be ahorizontal line. It is straightforward to see that, if we reflect the point set S around (cid:96) , then S becomes S (cid:48) and we have that RCH ( S (cid:48) ) is vertically separable.We will assume in each of the problems MaxRCH , MaxEmptyRCH , MaxAreaRCH , and
MaxWeightRCH that the optimal subset S ⊆ P is such that RCH ( S ) is vertically separable. To finish this sec-tion, we give one more definition. For every p, q ∈ P such that p ≺ q , let R p \ q , R q \ p , and R p,q be the subsets of P in the regions Q ( p ) \ Q ( q ), Q ( q ) \ Q ( p ), and Q ( p ) ∩ Q ( q ), respectively(see Figure 3, left). Observe that if r ∈ R p \ q then r ≺ q , if r ∈ R q \ p then p ≺ r , and if r ∈ R p,q then r (cid:54)≺ q and p (cid:54)≺ r . For every p, q ∈ P such that q ≺ (cid:48) p , we define R (cid:48) p \ q , R (cid:48) q \ p and R (cid:48) p,q as thesubsets of P in the regions Q ( q ) ∩ Q ( p ), Q ( q ) ∩ Q ( p ) and Q ( p ), respectively. p qR p \ q R q \ p R p,q q R (cid:48) q \ p p R (cid:48) p,q R (cid:48) p \ q p q C p,q Figure 3:
Left: Sets R p \ q , R q \ p , R p,q , R (cid:48) p \ q , R (cid:48) q \ p and R (cid:48) p,q . Right: Example of C p,q . In this section, we solve the
MaxRCH problem. Given P , our goal is to combine four staircasesin order to obtain a subset S of P whose rectilinear convex hull is of maximum size. All of thishas to be done carefully, since the occurrence of pinched points may lead to overcounting.Our algorithm to solve the MaxRCH problem proceeds in three steps: In the first step, wecompute the 2-staircases of maximum size for every p, q ∈ P such that p ≺ q . In the secondstep, we compute what we call a triple -staircase and a triple -staircase of maximum sizes(yet to be defined). In the third and last step, we show how to combine a triple 1-staircaseand a triple 3-staircase to solve the MaxRCH problem. In this step, we will make sure that thesolution thus obtained is vertically separable. Our algorithm will run in O ( n ) time and O ( n )space. We describe now in detail the steps of our algorithm. The first step:
For every p, q ∈ P such that p ≺ q or p = q , let C p,q be a 2-staircase withendpoints p and q of maximum size, see Figure 3, right. Let C p,q be the number of elements of P in C p,q . Note that C p,q equals the maximum number of 2-extremal points over all S ∪ { p, q } with S ⊆ P ( p, q ). We can easily calculate C p,q , for all p, q ∈ P with p ≺ q or p = q , in O ( n )time and O ( n ) space, using dynamic programming with the following recurrence: C p,q = (cid:26) if p = q max { C r,q } over all r ∈ P ( p, q ) ∪ { q } if p (cid:54) = q. (1)Using the elements C p,q , it is a routine matter to determine C p,q , for any p ≺ q . We note that using not so trivial methods, we can calculate all of the C p,q ’s in O ( n log n ) time. However,this yields no improvement on the overall time complexity of our algorithms. efinition 3.1. Given a point set S ⊆ P , we define the triple 1-staircase (resp., triple 3-staircase) associated with S as the concatenation of the -, - and -staircases (resp., the -, -and -staircases) associated with S . The second step:
In this step, our goal is to obtain a triple 1-staircase and a triple 3-staircase of maximum cardinality, starting and ending at some pairs of points of P . Triplestaircases allow us to conveniently manage pinched points and disconnections of the rectilinearconvex hull. Notice that the boundary of M ( S ) ∩ M ( S ) ∩ M ( S ) (except for its two infiniterays) always belongs to the triple 1-staircase associated with S .Consider p, q ∈ P such that p ≺ q or p = q . Let Z ( p, q ) = Q ( u ), where u = ( p x , q y ), andlet z ( p, q ) = Z ( p, q ) ∩ P . Let T p,q be the triple 1-staircase of maximum cardinality among allsubsets S ∪ { p, q } with S ⊆ z ( p, q ). If S (cid:48) ⊆ z ( p, q ) is the set associated with T p,q , observe that M ( S (cid:48) ∪ { p, q } ) ∩ M ( S (cid:48) ∪ { p, q } ) ∩ M ( S (cid:48) ∪ { p, q } ) may contain points in P ( p, q ), it may bedisconnected, and it may have pinched points (see Figure 4). Note that p and q are always theendpoints of T p,q . Let X p,q denote the set of extreme vertices of T p,q (that is, the set of 1-, 2-and 3-extremal points of S (cid:48) ∪ { p, q } ), and let T p,q be the cardinality of X p,q . p q p q p qp = q p q p q C p,q u u uu u Figure 4:
Examples of triple 1-staircases T p,q . We calculate all of the T p,q ’s by dynamic programming using Equations (2) and (3). Westore all of the T p,q ’s in a table T . If α p,q = 1 when p = q , and α p,q = 2 when p (cid:54) = q , then: T p,q = max C p,q (A) T r,q over all r ∈ R p \ q (B) T p,r over all r ∈ R q \ p (C) α p,q + T r,r over all r ∈ R p,q (D) α p,q + U p,r over all r ∈ R p,q (E) (2)where for every pair p, r ∈ P such that p ≺ (cid:48) rU p,r = max { T r,s } over all s ∈ R (cid:48) p \ r . (3)Values U p,r are stored in a table U . The next lemma shows the correctness of this recurrence. Lemma 3.2.
The recurrence (2) correctly calculates T p,q , the size of X p,q , in O ( n ) time and O ( n ) space. roof. Let T p,q be an optimal triple 1-staircase for a pair of points p, q ∈ P such that p ≺ q and let S (cid:48) ⊆ z ( p, q ) be the point set associated with T p,q . In the counter-clockwise traversalof the triple 1-staircase, let p − and q − be the elements of P that follow and precede p and q ,respectively. Hence, T p,q can be obtained as an extension of T p,q − , T p − ,q , or T p − ,q − .If p − , q − ∈ B ( p, q ), then necessarily T p,q is a 2-staircase (the 1 and 3-staircases of T p,q consistof only points p and q , respectively), so T p,q = C p,q and case (A) is used to set T p,q . Thus, weassume in the rest of the proof that at least one of p − and q − is not in B ( p, q ). See Figure 5for the cases. p qr p q r rp q rp q s (B) (C) (D) (E) T r,q T p,r T r,r T r,s U p,r Figure 5:
Cases in the recursive computation of T p,q . If p − ∈ R p \ q , then we have p − ≺ q and p − is not 3-extremal in T p − ,q . We use case (B) tofind a point r that plays the role of p − to compute the value of T p,q . If q − ∈ R q \ p , then we have p ≺ q − and q − is a point that is not 1-extremal in T p,q − . We use case (C) to find a point r thatplays the role of q − to compute the value of T p,q .Suppose now that p − is in R p,q (a similar reasoning applies if q − is in R p,q ). In this case, q − cannot be in B ( p, q ) and if q − ∈ R q \ p then we use case (C) . If q − ∈ R p,q , there are twocases to analyze: p − = q − and p − (cid:54) = q − . If p − = q − , then we can use case (D) to find a point r that plays the role of p − to compute the value of T p,q . When p − (cid:54) = q − , we prove that p − ≺ q − ,and then case (E) can be used to find a pair of points r and s playing the roles of p − and q − , both in R p,q , with maximum value T r,s . By Observation 2.3, as p and p − are consecutive1-extremal points, then Q ( o ) contains no element in S (cid:48) , where o = ( p − x , p y ). In particular,since q − is in R p,q , this implies that q − cannot be in either Q ( p − ) or Q ( p − ). Moreover,as q and q − are consecutive 3-extremal points, then Q ( o (cid:48) ) contains no element in S (cid:48) again byObservation 2.3, where o (cid:48) = ( q x , q − y ). As a consequence, q − cannot be in Q ( p − ), so we concludethat q − ∈ Q ( p − ).To compute tables T and U , we scan the elements of P from right to left. Each time anelement p ∈ P is encountered, we scan all of the q ∈ P such that p x < q x , again from right toleft. When p ≺ q we compute T p,q , and when p ≺ (cid:48) q we compute U p,q . Each entry of T and U is determined in O ( n ) time. Thus, U and T can be computed in overall O ( n ) time and O ( n )space. Cases (A) to (D) are in O ( n ). We charge the work done in case (E) to constructingtable U , which can be done in O ( n ) time per entry. Thus the entire complexity is in O ( n ) timeand O ( n ) space.In a totally analogous way, we can calculate triple 3-staircases of maximum size. For p ≺ q or p = q , let T (cid:48) p,q be the size of the triple 3-staircase T (cid:48) p,q of maximum cardinality among allsubsets S (cid:48) ∪ { p, q } , where S (cid:48) is now a subset of points of P in Q ( v ) with v = ( q x , p y ). Afterrotating the coordinates by π , observe that the triple 3-staircase T (cid:48) p,q is the triple 1-staircase T q,p . Thus, by symmetry with the T p,q ’s, all the T (cid:48) p,q ’s can also be calculated in O ( n ) time and O ( n ) space. The third step:
In this step, we show how to combine a triple 1-staircase and a triple7-staircase to solve the
MaxRCH problem. Recall that the solution must be vertically separable.Next we give the definition of a 4-separator and then we show that it is equivalent to verticalseparability.
Definition 3.3.
Let S ⊆ P be any subset with | S | ≥ . Given four (not necessarily distinct)extremal points p, q, r, s ∈ S , we say that the tuple ( p, q, r, s ) is a of RCH ( S ) if thefollowing five conditions are satisfied: (1) p ≺ q or p = q ; (2) q ≺ (cid:48) r ; (3) r ≺ s or r = s ; (4) p and r are consecutive points in the -staircase of S ; and (5) s and q are consecutive points inthe -staircase of S (see Figure 6). a d p r sb c T r,s a d p r sb c T r,s q T (cid:48) p,q q T (cid:48) p,q a d p r = s b c T s,s q T (cid:48) p,q p = q = a = dr s b c T r,s T (cid:48) p,p = { p } Figure 6:
Examples of 4-separators ( p, q, r, s ). The next lemma shows the equivalence between vertical separability and the existence of4-separators.
Lemma 3.4.
RCH ( S ) is vertically separable if and only if RCH ( S ) has a -separator.Proof. Let us first assume that
RCH ( S ) is vertically separable, that is, B ( a, d ) and B ( b, c ) areseparated by a vertical line. Recall that a , b , c , and d are the leftmost, bottommost, rightmost,and topmost points of S , respectively. Then, we can argue the following: If a ≺ d , then S has atleast one 1-extremal point to each side of the vertical line through d . Otherwise, if a = d , then S has at least one 1-extremal point to the right side. Thus, covering both cases, let p and r bethe two consecutive 1-extremal points of S such that p x ≤ d x < r x . Now, given that d x < r x ,we have that: If r is also 3-extremal, thus a pinched point, then S has at least one 3-extremalpoint to the left side of the vertical line through r . Otherwise, if r is not 3-extremal, then S has at least one 3-extremal point to each side of this line. Thus, we can define s and q as thetwo consecutive 3-extremal points of S such that q x < r x ≤ s x . It is straightforward to seenow that ( p, q, r, s ) is a 4-separator of RCH ( S ). Note that, when p = a = d , then necessarily q = p = a = d .Assume now that ( p, q, r, s ) is a 4-separator of RCH ( S ). We then have that: d ≺ (cid:48) q or d = q , and r ≺ (cid:48) b or r = b . These conditions, together with q ≺ (cid:48) r , directly imply that B ( a, d )and B ( b, c ) are separated by a vertical line, thus RCH ( S ) is vertically separable.8sing 4-separators, we show how to find an optimal solution that is vertically separable.Among all subsets S of P such that RCH ( S ) is vertically separable, let S be a subset of P such that RCH ( S ) has maximum size. Let ( p, q, r, s ) be a 4-separator of RCH ( S ). The keyobservation is that the vertices of T (cid:48) p,q ∪ T r,s are the set of extremal points of S . Note that T (cid:48) p,q ∩ T r,s = ∅ and | RCH ( S ) | , the size of RCH ( S ), is T (cid:48) p,q + T r,s .Thus, we proceed as follows: For given p, s ∈ P such that p x < s x , let S p,s be the rectilinearconvex hull of maximum size, among all subsets S ⊆ P containing p and s such that there existtwo points q, r ∈ S with ( p, q, r, s ) being a 4-separator of RCH ( S ). Let S p,s be the size of S p,s .Note that S p,s = T (cid:48) p,q + T r,s for some 4-separator ( p, q, r, s ). Then, the following equations allowus to calculate | RCH ( S ) | in O ( n ) time and O ( n ) space, as Theorem 3.5 proves: | RCH ( S ) | = max { S p,s } over all p, s ∈ P such that p x < s x (4)where for each pair of points p, s ∈ P with p x < s x S p,s = max { T (cid:48) p,q + T r,s } over all q, r ∈ P such that ( p, q, r, s ) is a 4-separator . (5) Theorem 3.5.
The
MaxRCH problem can be solved in O ( n ) time and O ( n ) space.Proof. According to Equations (4) and (5), we only need to show how to compute S p,s in lineartime, for given p and s . Let Q p be the set of all points q ∈ P such that q ≺ (cid:48) s , and p ≺ q or p = q . Let Q s be the set of all points r ∈ P such that p ≺ (cid:48) r , and r ≺ s or r = s . Note that Q p ∩ Q s = ∅ and that p and s belong to Q p and Q s , respectively, only when p y > s y . Let L p,s be the list of the elements of Q p ∪ Q s sorted by x -coordinate. Observe that if ( p, q, r, s ) is a4-separator of RCH ( S p,s ), then r ∈ Q s , q ∈ Q p , and q is the point q ∗ ∈ Q p from the beginningof L p,s to r such that T (cid:48) p,q ∗ + T r,s = max { T (cid:48) p,q (cid:48) + T r,s } over all q (cid:48) ∈ Q p from the beginning of L p,s to r .We calculate S p,s by processing the elements of L p,s in order. For an element t in L p,s , let q ∗ t be the point in Q p maximizing T (cid:48) p,q (cid:48) over all q (cid:48) ∈ Q p from the beginning of L p,s to t (including t ). When processing a point t , observe that if t ∈ Q p , then q ∗ t is either t or q ∗ t − . Otherwise,if t ∈ Q s , then q ∗ t = q ∗ t − . Moreover, if t ∈ Q s , then we set q = q ∗ t and r = t , and consider( p, q, r, s ) as a feasible S p,s . After processing the last element of L p,s , amongall the (linear number) feasible separators, we return the solution S p,s induced by the feasibleseparator that maximizes T (cid:48) p,q + T r,s . Thus, S p,s can be calculated in O ( n ) time, once tables T and T (cid:48) have been constructed. In this section, we show how to adapt the algorithm of Section 3 to solve the
MaxEmptyRCH ,the
MaxAreaRCH and the
MaxWeightRCH problems. The first observation is that, as the opti-mal solution for any of these problems is the rectilinear convex hull of a subset S of P , thenLemmas 2.5 and 3.4 hold. This implies that we can assume that B ( a, d ) and B ( b, c ) are sepa-rated by a vertical line, so a 4-separator exists for the optimal solution in any of the problems.As a consequence, the algorithms to solve these three problems follow the same scheme as thealgorithm described in the previous section, and we only need to show how to adapt in eachproblem the calculation of the 2-staircases, the triple 1- and 3-staircases and the rectilinearconvex hulls S p,s to fulfill the requirements on emptiness, area or weight.We start by solving the MaxEmptyRCH problem, we continue with the
MaxAreaRCH problemand we finish with the
MaxWeightRCH problem.9 .1 Maximum size empty rectilinear convex hull
To solve the
MaxEmptyRCH problem in O ( n ) time and O ( n ) space, we modify the steps ofour previous algorithm. These modifications ensure that the “interiors” of the triple 1- and 3-staircases and the rectilinear convex hulls are empty. Recall that in this problem we are lookingfor a subset S ⊆ P such that RCH ( S ) has maximum size and there is no element of P in theinterior of RCH ( S ). The first step:
For a pair of points p, q ∈ P such that p ≺ q or p = q , we say that the2-staircase associated with a subset S of P ( p, q ) is empty if no point of P is in the interior of B ( p, q ) ∩ M ( S ∪ { p, q } ), see Figure 7, left. p C p,q qru a d p r s b c T r,s q T (cid:48) p,q q v u Figure 7:
Left: Example of C p,q when the 2-staircases must be empty. Right: Third step of the algorithmwhen the interior must be empty of elements of P . Let C p,q be the empty 2-staircase of maximum cardinality over all subsets S ∪ { p, q } with S ⊆ P ( p, q ), and let C p,q be the size of C p,q . Observe that if u is the point ( p x , q y ) and r ∈ P isthe vertex of the 2-staircase that follows p , then P ( r, u ) = ∅ . Thus, values C p,q can be computedusing the following recurrence: C p,q = (cid:26) if p = q max { C r,q } over all r ∈ P ( p, q ) ∪ { q } such that P ( r, u ) = ∅ if p (cid:54) = q. (6)As q and u are on the same horizontal line, P ( q, u ) is not defined. In this case, we assume that P ( q, u ) is the empty set. Using standard range counting techniques [13], we can preprocess thegrid G generated by the vertical and horizontal lines through the elements of P in O ( n ) timeand space, so that for every pair of vertices u, v of G we can query the number of points in P ( u, v ) in O (1) time. Thus, we can decide whether P ( u, v ) = ∅ in O (1) time. Therefore, values C p,q can be calculated in O ( n ) time and O ( n ) space. The second step:
For every p, q ∈ P such that p ≺ q or p = q , we say that the triple1-staircase T corresponding to a subset S of z ( p, q ) is empty if the (disconnected) region O T = Z ( p, q ) ∩ M ( S ∪ { p, q } ) ∩ M ( S ∪ { p, q } ) ∩ M ( S ∪ { p, q } ) associated with T contains no elementof P . Please, refer to Figure 4, where the shaded areas correspond to O T . Let T p,q be the emptytriple 1-staircase of maximum size among all subsets S ∪ { p, q } , with S ⊆ z ( p, q ). Let E ( p, q, r )denote the interior of B ( p, q ) ∩ Q ( r ) if p (cid:54) = q , and the empty set if p = q . In Figure 5 examplesof open rectangles E ( p, q, r ) are shown as shaded rectangles . We show how to compute T p,q , thecardinality of the set of extreme vertices of T p,q , using the following equations that are similar10o Equations (2) and (3): T p,q = max C p,q (A) T r,q over all r ∈ R p \ q : P ∩ E ( p, q, r ) = ∅ (B) T p,r over all r ∈ R q \ p : P ∩ E ( p, q, r ) = ∅ (C) α p,q + T r,r over all r ∈ R p,q : P ∩ E ( p, q, r ) = ∅ (D) α p,q + U p,r over all r ∈ R p,q : P ∩ E ( p, q, r ) = ∅ (E) (7)where for every pair p, r ∈ P such that p ≺ (cid:48) rU p,r = max { T r,s } over all s ∈ R (cid:48) p \ r . (8)In case (A) , O p,q is empty as C p,q is an empty 2-staircase. Equation (7) is obtained fromEquation (2) by further constraining r in the cases from (B) to (E) to satisfy P ∩ E ( p, q, r ) = ∅ .This guarantees that the interior of O p,q is empty of elements of P for all p, q . Verifying that P ∩ E ( p, q, r ) = ∅ can be decided in O (1) time by using a range counting query. The proof ofcorrectness of Equations (7) and (8) follows the same steps as in Lemma 3.2. Hence, computingthe new table T can be done in O ( n ) time and O ( n ) space. By symmetry, values in T (cid:48) p,q , thesizes of the empty triple 3-staircases T (cid:48) p,q , can also be calculated in O ( n ) time and O ( n ) space. The third step:
For given p, s ∈ P such that p x < s x , let S p,s be the empty rectilinearconvex hull of maximum size, among all subsets S ⊆ P containing p and s such that RCH ( S )is empty and there exist two points q, r ∈ S with ( p, q, r, s ) being a 4-separator of RCH ( S ). Let S p,s denote the size of S p,s . To compute S p,s we have to distinguish whether p ≺ (cid:48) s or p ≺ s .If p ≺ (cid:48) s (see Figure 6, top-right, or any in the bottom), then S p,s = max { T (cid:48) p,q + T r,s } over all4-separators ( p, q, r, s ). Otherwise, if p ≺ s (see Figure 7, right), then we must ensure that each4-separator ( p, q, r, s ) satisfies P ( u, v ) = ∅ , where u = ( r x , s y ) and v = ( q x , p y ).If S is a subset of P such that RCH ( S ) is empty, vertically separable and of maximumsize, the new equations to compute | RCH ( S ) | are: | RCH ( S ) | = max { S p,s } over all p, s ∈ P with p x < s x (9)where for each pair of points p, s ∈ P such that p x < s x S p,s = (cid:26) max { T (cid:48) p,q + T r,s } : ( p, q, r, s ) is a 4-separator p ≺ (cid:48) s max { T (cid:48) p,q + T r,s } : ( p, q, r, s ) is a 4-separator, P ( u, v ) = ∅ p ≺ s. (10) Theorem 4.1.
The
MaxEmptyRCH problem can be solved in O ( n ) time and O ( n ) space.Proof. Again, we only need to show that given points p and s S p,s can be computed in lineartime. When p ≺ (cid:48) s , we argue as in the proof of Theorem 3.5. However, when p ≺ s , we needto only consider 4-separators such that P ( u, v ) = ∅ . Let Q p,s = { t ∈ P : p ≺ t ≺ s } , whichsatisfies Q p,s ∩ Q p = ∅ and Q p,s ∩ Q s = ∅ . Recall that Q p ∩ Q s = ∅ and that, when p ≺ s , Q p = { q ∈ P : p ≺ q, q ≺ (cid:48) s } and Q s = { r ∈ P : r ≺ s, p ≺ (cid:48) r } . Let L p,s be the list of thepoints of Q p ∪ Q s ∪ Q p,s sorted by x -coordinate. Assuming that we have already sorted P by x -coordinate L p,s is obtained in O ( n ) time.As before, we calculate S p,s by processing the elements of L p,s in order. For an element t in L p,s , let q ∗ t be the point in Q p maximizing T (cid:48) p,q (cid:48) over all q (cid:48) ∈ Q p from the beginning of L p,s to t (including t ) subject to there being no elements of Q p,s in L p,s from q (cid:48) to t . When processinga point t ∈ Q p,s , we set q ∗ t = nil denoting that q ∗ t is undefined. Observe that, when processinga point t ∈ Q p , if q ∗ t − = nil then q ∗ t = t , and if q ∗ t − (cid:54) = nil then q ∗ t is either t or q ∗ t − . Whenprocessing a point t ∈ Q s , then q ∗ t = q ∗ t − , and if q ∗ t − (cid:54) = nil , then we set q = q ∗ t and r = t ,and consider ( p, q, r, s ) as a feasible 4-separator of S p,s . Note that for this 4-separator we have P ( u, v ) = ∅ . After processing all elements in L p,s , S p,s is determined by a feasible 4-separatorthat maximizes T (cid:48) p,q + T r,s . 11 .2 Maximum area empty rectilinear convex hull In the
MaxAreaRCH problem, we determine an empty rectilinear convex hull of maximum area.To solve this problem, we proceed as in the previous subsection. The only difference is that wesum areas in all of our recurrences, instead of counting points. Given a bounded set Z ⊂ R ,we denote the area of Z as Area ( Z ).Now, C p,q , T p,q , T (cid:48) p,q and S p,q are as described in Section 4.1, with the difference thatthey maximize area instead of maximizing size. The areas are defined as follows. If S = { p, v , . . . , v k − , q } is the set of vertices of an empty 2-staircase, we define the area of this stair-case as Area ( B ( p, q ) ∩ M ( S )). For an empty triple 1-staircase or an empty triple 3-staircase T ,its area is the area of its associated region O T . The area of a rectilinear convex hull is the areaof its interior. The first step:
For a pair of points p, q ∈ P such that p ≺ q or q = p , we compute C p,q ,the area of C p,q , using the following recurrence, which is a variant of Equation (6) maximizingarea: C p,q = (cid:26) if p = q max r ∈ P ( p,q ) ∪{ q } { Area ( B ( r, u )) + C r,q } : P ( r, u ) = ∅ if p (cid:54) = q. (11)where u = ( p x , q y ). As B ( q, u ) is not defined, we set Area ( B ( q, u )) = 0. The second step:
For every p, q ∈ P such that p ≺ q or p = q , let T p,q be the area of T p,q .All T p,q ’s can be calculated in O ( n ) time and O ( n ) space using the following equations, whichare variants of Equations (7) and (8) maximizing area (recall that if p = q , then E ( p, q, r ) = ∅ ,so its area is 0): T p,q = max C p,q (A) Area ( E ( p, q, r )) + T r,q over all r ∈ R p \ q : P ∩ E ( p, q, r ) = ∅ (B) Area ( E ( p, q, r )) + T p,r over all r ∈ R q \ p : P ∩ E ( p, q, r ) = ∅ (C) Area ( E ( p, q, r )) + T r,r over all r ∈ R p,q : P ∩ E ( p, q, r ) = ∅ (D) Area ( E ( p, q, r )) + U p,r over all r ∈ R p,q : P ∩ E ( p, q, r ) = ∅ (E) (12)where for every pair p, r ∈ P such that p ≺ (cid:48) rU p,r = max { T r,s } over all s ∈ R (cid:48) p \ r . (13)The areas T (cid:48) p,q for the empty triple 3-staircases T (cid:48) p,q can be calculated in a similar way. The third step:
Let S p,s be the area of S p,s . Recall that, for given p, s ∈ P such that p x < s x , S p,s is the empty rectilinear convex hull of maximum area, among all subsets S ⊆ P containing p and s such that RCH ( S ) is empty and there exist two points q, r ∈ S with ( p, q, r, s )a 4-separator of RCH ( S ). Observe that if p ≺ (cid:48) s , then S p,s = T (cid:48) p,q + T r,s for some 4-separator( p, q, r, s ). Otherwise, if p ≺ s then S p,s = Area ( B ( u, v )) + T (cid:48) p,q + T r,s for some 4-separator( p, q, r, s ), subject to P ( u, v ) = ∅ , where u = u ( r ) = ( r x , s y ) and v = v ( q ) = ( q x , p y ) (seeFigure 7, right).Given that Area ( B ( u, v )) depends on both r and q , using the inclusion/exclusion principle,we can then calculate S p,s as S p,s = T (cid:48) p,q + Area ( B ( v, s )) + T r,s + Area ( B ( p, u )) − Area ( B ( p, s )) . Since p and s are fixed, note that U ( p, q, s ) = T (cid:48) p,q + Area ( B ( v ( q ) , s )) depends only on q and V ( p, r, s ) = T r,s + Area ( B ( p, u ( r ))) − Area ( B ( p, s )) depends only on r . Each of these two valuescan be computed in O (1) time, once T and T (cid:48) have been computed in the second step. If S isa subset of P such that RCH ( S ) is empty, vertically separable and of maximum area, the newequations to compute RCH ( S ) are: | RCH ( S ) | = max { S p,s } over all p, s ∈ P with p x < s x , (14)12here for each pair of points p, s ∈ P such that p x < s x S p,s = (cid:26) max { p, q, r, s ) } { T (cid:48) p,q + T r,s } p ≺ (cid:48) s max { p, q, r, s ) } { U ( p, q, s ) + V ( p, r, s )) } : P ( u ( r ) , v ( q )) = ∅ p ≺ s. (15) Theorem 4.2.
The
MaxAreaRCH problem can be solved in O ( n ) time and O ( n ) space.Proof. The proof follows the proof of Theorem 4.1. The only difference is that, when processingan element t in L p,s , q ∗ t is the point in Q p maximizing T (cid:48) p,q (cid:48) + Area ( B ( v ( q (cid:48) ) , s )), instead ofmaximizing T (cid:48) p,q (cid:48) . After processing all elements in L p,s , S p,s is determined by a feasible 4-separator that maximizes T (cid:48) p,q + Area ( B ( v, s )) + T r,s + Area ( B ( p, u )) − Area ( B ( p, s )). In the
MaxWeightRCH problem, each input point p of P is comes with a (positive or negative)weight w ( p ). We determine a subset S ⊆ P such that RCH ( S ) has maximum weight, thatis, such that (cid:80) p ∈ P ∩ RCH ( S ) w ( p ) is maximized. The algorithm to solve this problem combinesthe ideas of the previous algorithms and follows the same steps, however, now we add weights.We define Weight ( Z ) = (cid:80) p ∈ P ∩ Z w ( p ) as the weight of a region Z ⊂ R . Using the same rangecounting techniques [13] as in Section 3, we can preprocess the grid G generated by the verticaland horizontal lines through the elements of P in O ( n ) time and space, so that for every pairof vertices u, v of G we can query Weight ( B ( u, v )) = (cid:80) p ∈ P ( u,v ) w ( p ) in O (1) time.Now, C p,q , T p,q , T (cid:48) p,q and S p,q are as described in Section 3, except that weight is maximized.The weights are defined as follows. If S = { p, v , . . . , v k − , q } is the set of vertices of a 2-staircase, its weight is defined as w ( p ) + w ( q ) + Weight ( B ( p, q ) ∩ M ( S )). Note that the weightsof all points in S are included in this formulae. For a triple 1-staircase or a triple 3-staircase T , its weight is the addition of the weights of the points of P that appear on the boundary orin the interior of O T , the region associated with T . Finally, the weight of a rectilinear convexhull is the addition of the points of P on its boundary or interior. The first step: If C p,q is the weight of C p,q , for a pair of points p, q ∈ P such that p ≺ q or q = p , all C p,q ’s can be computed in O ( n ) time and O ( n ) space using the following recurrence: C p,q = (cid:26) w ( p ) if p = qw ( p ) + max r ∈ P ( p,q ) ∪{ q } { Weight ( B ( r, u )) + C r,q } if p (cid:54) = q. (16)where u = ( p x , q y ). We set Weight ( B ( q, u )) = 0 as B ( q, u ) is not defined. The second step: If T p,q is the weight of T p,q , for every p, q ∈ P such that p ≺ q or p = q ,then all T p,q ’s (and, by symmetry, all T (cid:48) p,q ’s) can be calculated in O ( n ) time and O ( n ) spaceusing the following equations, where α p,q = w ( p ) if p = q , and α p,q = w ( p ) + w ( q ) if p (cid:54) = q : T p,q = max C p,q (A) w ( p ) + Weight ( E ( p, q, r )) + T r,q over all r ∈ R p \ q (B) w ( q ) + Weight ( E ( p, q, r )) + T p,r over all r ∈ R q \ p (C) α p,q + Weight ( E ( p, q, r )) + T r,r over all r ∈ R p,q (D) α p,q + Weight ( E ( p, q, r )) + U p,r over all r ∈ R p,q (E) (17)where for every pair p, r ∈ P such that p ≺ (cid:48) rU p,r = max { T r,s } over all s ∈ R (cid:48) p \ r . (18) The third step:
For given p, s ∈ P such that p x < s x , let S p,s be the weight of S p,s . Usingsimilar reasoning as in the previous subsection, one can show that, if S is a subset of P such13hat RCH ( S ) is vertically separable of maximum weight, the following equations calculate | RCH ( S ) | : | RCH ( S ) | = max { S p,s } over all p, s ∈ P such that p x < s x (19)where for each pair of points p, s ∈ P such that p x < s x S p,s = (cid:26) max { p, q, r, s ) } { T (cid:48) p,q + T r,s } p ≺ (cid:48) s max { p, q, r, s ) } { U ( p, q, s ) + V ( p, r, s )) } p ≺ s. (20)Now U ( p, q, s ) = T (cid:48) p,q + Weight ( B ( v ( q ) , s )) and V ( p, r, s ) = T r,s + Weight ( B ( p, u ( r ))) − Weight ( B ( p, s )),with u = u ( r ) = ( r x , s y ) and v = v ( q ) = ( q x , p y ). The proof of the next theorem is a straight-forward adaptation of the previous arguments. Theorem 4.3.
The
MaxWeightRCH problem can be solved in O ( n ) time and O ( n ) space. References [1] O. Aichholzer, R. Fabila-Monroy, H. Gonz´alez-Aguilar, T. Hackl, M. A. Heredia, C. Hue-mer, J. Urrutia, P. Valtr, and B. Vogtenhuber. On k -gons and k -holes in point sets. Computational Geometry , 48 (7), 2015, 528–537.[2] O. Aichholzer, R. Fabila-Monroy, H. Gonz´alez-Aguilar, T. Hackl, M. A. Heredia, C. Hue-mer, J. Urrutia, and B. Vogtenhuber. 4-holes in point sets.
Computational Geometry ,47(6), 2014, 644–650.[3] O. Aichholzer, R. Fabila-Monroy, T. Hackl, C. Huemer, A. Pilz, and B. Vogtenhuber.Lower bounds for the number of small convex k -holes. Computational Geometry , 47(5),2014, 605–613.[4] C. Alegr´ıa-Galicia, D. Orden, C. Seara, and J. Urrutia. Efficient computation of minimum-area rectilinear convex hull under rotation and generalizations.
CoRR , abs/1710.10888,2017.[5] D. Avis and D. Rappaport. Computing the largest empty convex subset of a set of points.
Proceedings of the 1st Annual Symposium on Computational Geometry , 1985, 161–167.[6] C. Bautista-Santiago, J. M. D´ıaz-B´a˜nez, D. Lara, P. P´erez-Lantero, J. Urrutia, and I.Ventura. Computing optimal islands.
Operations Research Letters , 39(4), 2011, 246–251.[7] P. Brass, W. Moser, and J. Pach.
Convex polygons and the Erd˝os-Szekeres problem . Chap-ter 8.2 in the book Research problems in discrete geometry. 2005, Springer.[8] V. Chv´atal and G. Klincsek. Finding largest convex subsets.
Congressus Numerantium ,29, 1980, 453–460.[9] P. Erd˝os and G. Szekeres. A combinatorial problem in geometry.
Compositio mathematica ,2, 1935, 463–470.[10] E. Fink and D. Wood.
Restricted-orientation Convexity . Monographs in Theoretical Com-puter Science (An EATCS Series), Springer-Verlag, 2004.[11] W. Morris and V. Soltan. The Erd˝os-Szekeres problem on points in convex position–Asurvey.
Bulletin of the American Mathematical Society , 37(4), 2000, 437–458.1412] T. Ottmann, E. Soisalon-Soininen, and D. Wood. On the definition and computation ofrectilinear convex hulls.
Information Sciences , 33(3), 1984, 157–171.[13] F. P. Preparata and M. I. Shamos.
Computational geometry: An introduction , 2012,Springer Science & Business Media.[14] G. J. E. Rawlins and D. Wood. Ortho-convexity and its generalizations.