Rainbow polygons for colored point sets in the plane

Given a colored point set in the plane, a perfect rainbow polygon is a simple polygon that contains exactly one point of each color, either in its interior or on its boundary. Let $\operatorname{rb-index}(S)$ denote the smallest size of a perfect rainbow polygon for a colored point set $S$, and let $\operatorname{rb-index}(k)$ be the maximum of $\operatorname{rb-index}(S)$ over all $k$-colored point sets in general position; that is, every $k$-colored point set $S$ has a perfect rainbow polygon with at most $\operatorname{rb-index}(k)$ vertices. In this paper, we determine the values of $\operatorname{rb-index}(k)$ up to $k=7$, which is the first case where $\operatorname{rb-index}(k)\neq k$, and we prove that for $k\ge 5$, \[ \frac{40\lfloor (k-1)/2 \rfloor -8}{19} %Birgit: \leq\operatorname{rb-index}(k)\leq 10 \bigg\lfloor\frac{k}{7}\bigg\rfloor + 11. \] Furthermore, for a $k$-colored set of $n$ points in the plane in general position, a perfect rainbow polygon with at most $10 \lfloor\frac{k}{7}\rfloor + 11$ vertices can be computed in $O(n\log n)$ time.


Introduction
Given a colored point set in the plane, in this paper we study the problem of finding a simple polygon containing exactly one point of each color. Formally, the problem we consider is the following. Let k ≥ 2 be an integer and let {1, . . . , k} be k distinct colors. For every 1 ≤ i ≤ k, let S i denote a finite set of points of color i in the plane. We always assume that S i is nonempty and finite for all i ∈ {1, . . . , k}, and that S = k i=1 S i is in general position (that is, no three points of S are collinear).
This work has received funding from the European Union's Horizon 2020 research and innovation programme under the Marie Sk lodowska-Curie grant agreement No 734922.
For a simple polygon P with m vertices (or a simple m-gon) and a point x in the plane, we say that P contains x if x lies in the interior or on the boundary of P . Given a k-colored point set S = k i=1 S i and a simple polygon P in the plane, we call P a rainbow polygon for S if P contains at most one point of each color; and P will be called a perfect rainbow polygon if it contains exactly one point of each color. The perfect rainbow polygon problem for a colored point set S is that of finding a perfect rainbow polygon with the minimum number of vertices.
One can easily check that a perfect rainbow polygon always exists for a colored point set. A way of constructing such a polygon is described below, using the following well-known property for a plane tree: From a tree T embedded in the plane with straight-line edges, a simple polygon can be built by traversing the boundary of the unbounded face of T , placing a copy of a vertex infinitesimally close to that vertex each time it is visited, and connecting the copies according to the traversal order. One can imagine this simple polygon as the "thickening" of the tree. Thus, for a colored point set S, to build a perfect rainbow polygon we can choose one point of each color, form a star connecting one of these points to the rest, and thicken the star; see Figure 1a. Note that the simple polygon obtained in this way can be as close to the star as we wish, so that it contains no other points in S, apart from the points in S that we have chosen.
However, finding a perfect rainbow polygon of minimum size for a given colored point set (where the size of a polygon is the number of its vertices) is in general much more difficult. We believe that this problem is NP-complete. Therefore, we focus on giving combinatorial bounds for the size of minimum perfect rainbow polygons. Let rb-index(S) denote the rainbow index of a colored point set S; that is, the smallest size of a perfect rainbow polygon for S. We then define the rainbow index of k, denoted by rb-index(k), to be the largest rainbow index among all the k-colored point sets S; that is, rb-index(k) = max {rb-index(S) : S is a k-colored point set}. (1) In other words, rb-index(k) is the smallest integer such that, for every k-colored point set S, there exists a perfect rainbow polygon of size at most rb-index(k). The two main results in this paper are the following. First, we determine the values of the rainbow index up to k = 7, which is the first case where rb-index(k) = k, namely k 3 4 5 6 7 rb-index(k) 3 4 5 6 8 Second, we prove the following lower and upper bounds for the rainbow index 40 (k − 1)/2 − 8 19 ≤ rb-index(k) ≤ 10 k 7 + 11.
Furthermore, for a k-colored set of n points in the plane, a perfect rainbow polygon of size meeting these upper bounds can be computed in O(n log n) time. The rainbow index for small values of k is analyzed in Section 3. In Sections 4 and 5, we provide our upper and lower bounds for the rainbow index, respectively. These bounds are based on the analysis of the complexity of noncrossing covering trees for sets of points, under a new measure defined in this paper. This measure and the relationship between perfect rainbow polygons and noncrossing covering trees is given in Section 2.

Related previous work
Starting from the celebrated Ham-Sandwich theorem, a considerable amount of research about discrete geometry on colored point sets (or mass distributions) has been done. For instance,  Figure 1: (a) Thickening a tree to obtain a perfect rainbow polygon. Different colors are represented by different geometric objects. (b) A noncrossing covering tree for the eight black points that can be partitioned into five segments, s 1 = u 1 u 8 , s 2 = u 2 u 3 , s 3 = u 2 u 4 , s 4 = u 2 u 5 , and s 5 = u 6 u 7 ; and two forks, u 6 with multiplicity 1 and u 2 with multiplicity 2.
given cg red points and dg blue points in the plane, where c, d, and g are positive integers, the Equitable Subdivision Theorem establishes that there exists a subdivision of the plane into g convex regions such that each region contains precisely c red points and d blue points [10,34]. It is also known that every d-colored set of points in general position in R d can be partitioned into n subsets with disjoint convex hulls such that the set of points and all color classes are partitioned as evenly as possible [12]. For a wide range of geometric partitioning results, the reader is referred to [6,7,8,10,12,21,24,25,30,34] and the references therein.
In addition to geometric partitions, for colored points in the plane some research focuses on geometric structures covering the points in some specific way. For instance, covering the colored points with noncrossing monochromatic matchings [18], noncrossing heterochromatic matchings [26], noncrossing alternating cycles and paths [29], noncrosing alternating spanning trees [11,26] or noncrossing K 1,3 stars [1]. In other papers, the main goal is selecting k points with k distinct colors (a rainbow subset) from a k-colored point set such that some geometric properties of the rainbow subset are maximized or minimized. Rainbow subsets with maximum diameter are investigated in [19,23], with minimum diameter in [20,33], and rainbow subsets optimizing matchings under several criteria are studied in [9]. In addition, several traditional geometric problems for uncolored point sets become NP-hard for colored point sets. For instance, the following problems are NP-complete [23]: Computing a rainbow subset minimizing (maximizing) the length of its minimum spanning tree, computing a rainbow subset minimizing its convex hull, or computing a rainbow subset maximizing the distance between its closest pair.
Given a 3-colored point set R ∪ B ∪ G consisting of red, blue, and green points in the plane, a well-known result is that there exists an empty heterochromatic triangle, where the three vertices have distinct colors [15]. In particular, a heterochromatic triangle of minimum area cannot contain any other point from R ∪ B ∪ G in its interior, hence its interior is empty, and its boundary contains exactly one point of each color. This implies that rb-index(3) = 3. Related work [7] deals with colored lines instead of colored points, showing that in an arrangement of 3-colored lines, there always exists a line segment intersecting exactly one line of each color. Aloupis et al. [4] study the problem of coloring a given point set with k colors so that every axis-aligned strip containing sufficiently many points contains a point from each color class.

Covering trees versus perfect rainbow polygons
Given a set of (monochromatic) points, in this section we derive a lower bound for the size of simple polygons that contain the given points and have arbitrarily small area. We also provide a lower bound for the size of a perfect rainbow polygon for some colored point sets.
A noncrossing covering tree for a set S of points in the plane is a noncrossing geometric tree (that is, a plane straight-line tree) such that every point of S lies at a vertex or on an edge of the tree; see Figure 1b. Let T be a noncrossing covering tree whose vertices can be collinear. Similarly to [16], we define a segment of T as a path of collinear edges in T . Two segments of T may cross at a vertex of degree 4 or higher; we are interested in pairwise noncrossing segments. Any vertex of degree two and incident to two collinear edges can be suppressed; consequently, we may assume that T has no such vertices.
Let M be a partition of the edges of T into the minimum number of pairwise noncrossing segments. Let s = s(T ) denote the number of segments in M. A fork of T (with respect to M) is a vertex v that lies in the interior of a segment ab ∈ M and is an endpoint of another segment in M. The multiplicity of a fork v is 2 if it is the endpoint of two segments that lie on opposite sides of the supporting line of ab; otherwise its multiplicity is 1. See Figure 1b for an example.
Let t = t(T ) denote the sum of multiplicities of all forks in T with respect to M. We express the number of vertices in a polygon that encloses a noncrossing covering tree T in terms of the parameters s and t. If all edges of T are collinear, then s = 1 and T can be enclosed in a triangle. The following lemma addresses the case that s ≥ 2.
Lemma 1. Let T be a noncrossing covering tree and M a partition of the edges into the minimum number of pairwise noncrossing segments. If s ≥ 2 and t ≥ 0, then for every ε > 0, there exists a simple polygon P with 2s + t vertices such that area(P ) ≤ ε and T lies in P .
Proof. Let δ > 0 be the sufficiently small constant (specified below). For every vertex v of T , let D v be a disk of radius δ centered at v. We may assume that δ > 0 is so small that the disks D v , v ∈ V (T ), are pairwise disjoint, and each D v intersects only the edges of T incident to v. Then the edges of T incident to v partition D v into deg(v) sectors. If deg(v) ≥ 3, at most one of the sectors subtends a flat angle (that is, an angle equal to π). If deg(v) ≤ 2, none of the sectors subtends a flat angle by assumption. Conversely, if one of the sectors subtends a flat angle, then the two incident edges are collinear; they are part of the same segment (by the minimality of M), and hence v is a fork of multiplicity 1.
In every sector that does not subtend a flat angle, choose a point in D v on the angle bisector. By connecting these points in counterclockwise order along T , we obtain a simple polygon P that contains T . Note that P lies in the δ-neighborhood of T , so area(P ) is less than the area of the δ-neighborhood of T . The δ-neighborhood of a line segment of length has area 2 δ + πδ 2 . The δ-neighborhood of T is the union of the δ-neighborhoods of its segments. Consequently, if L is the addition of the lengths of all segments in M, then the area of the δ-neighborhood of T is bounded above by 2Lδ + sπδ 2 , which is less than ε if δ > 0 is sufficiently small.
It remains to show that P has 2s + t vertices; that is, the total number of sectors whose angle is not flat is precisely 2s + t. We define a perfect matching between the vertices of P and the set of segment endpoints and forks (with multiplicity) in each disk D v independently for every vertex v of T . If v is not a fork, then D v contains deg(v) vertices of P and deg(v) segment endpoints. If v is a fork of multiplicity 1, then D v contains deg(v)−1 vertices of P and deg(v)−2 segment endpoints. Finally, if v is a fork of multiplicity 2, then D v contains deg(v) vertices of P and deg(v) − 2 segment endpoints. In all cases, there is a one-to-one correspondence between the vertices in P lying in D v and the segment endpoints and forks (with multiplicity) in D v . Consequently, the number of vertices in P equals the sum of the multiplicities of all forks plus the number of segment endpoints, which is 2s + t, as required.
Next, we establish a relation between point sets and covering trees.
Lemma 2. Let S be a finite set of points in the plane, not all on a line. Then there exists an ε > 0 such that if S is contained in a simple polygon P with m vertices and area(P ) ≤ ε, then S admits a noncrossing covering tree T and a partition of the edges into pairwise noncrossing segments such that 2s + t ≤ m.
Proof. Let m ≥ 3 be an integer such that for every n ∈ N, there exists a simple polygon P n with precisely m vertices such that S ⊂ int(P n ) and area(P n ) ≤ 1 n . The real projective plane P R 2 is a compactification of R 2 . By compactness, the sequence (P n ) n≥3 contains a convergent subsequence of polygons in P R 2 . The limit is a weakly simple polygon P with precisely m vertices (some of which may coincide) such that S ⊂ P and area(P ) = 0. The edges of P form a set of pairwise noncrossing line segments (albeit with possible overlaps) whose union is a connected set that contains S. In particular, the union of the m edges of P forms a noncrossing covering tree T for S. The transitive closure of the overlap relation between the edges of P is an equivalence relation; the union of each equivalence class is a line segment. These segments are pairwise noncrossing (since the edges of P are pairwise noncrossing), and yield a covering of T with a set M of pairwise nonoverlapping and noncrossing segments. Analogously to the proof of Lemma 1, at each vertex v of T , there is a one-to-one correspondence between the vertices in P located at v and the segment endpoints and forks (with multiplicity) located at v. This implies 2s + t = m with respect to M.
An immediate consequence of Lemma 2 is a lower bound on the size of simple polygons with arbitrarily small area that enclose a point set S. Corollary 3. Let S be a finite set of points in the plane, not all on a line, and let T be a noncrossing covering tree for S minimizing 2s + t = m . Then there exists an ε > 0 such that if S is contained in a simple polygon P with m vertices and area(P ) ≤ ε, then m ≤ m.
Proof. By Lemma 2, there exists an ε > 0 such that if a simple polygon P with m vertices and area(P ) ≤ ε contains S, then P also contains a noncrossing covering tree for S. Therefore, by the minimality of T , necessarily m ≤ m.
A similar lower bound can be established for perfect rainbow polygons. In particular, for every set S of k points in the plane one can build a (k + 1)-colored point set S, such that finding a noncrosing covering tree for S minimizing 2s + t is equivalent to finding a minimum perfect rainbow polygon for S. Theorem 4. Let S be a set of k points in general position in the plane, and let T be a noncrossing covering tree for S minimizing 2s + t = m . Then there exists a (k + 1)-colored point set S such that every perfect rainbow polygon for S has at least m vertices.
Proof. Note that m ≤ 2k since a star centered at one of the points of S is a covering tree for S with k − 1 segments and no forks. By Lemma 2, there is an ε > 0 such that if S is contained in a simple polygon P with m vertices and area(P ) ≤ ε, then S admits a noncrossing covering tree and a partition of its edges into segments such that 2s + t ≤ m.
We construct a (k + 1)-colored point set S from the points in S by adding a dense point set S k+1 . Each point of S has a unique color and all points in S k+1 have the same color. Specifically, S k+1 is the union of two disjoint ε/(2k)-nets for the range space of triangles [32]; that is, every triangle of area ε/(2k) or more contains at least two points in S k+1 . Now suppose, for the sake of contradiction, that there exists a perfect rainbow polygon P for S with x vertices where x < m . Triangulate P arbitrarily into x − 2 triangles. The area of the largest triangle is at least area(P )/(x − 2). Since this triangle contains at most one point from S k+1 , we have area(P )/(x − 2) ≤ ε/(2k), and so area(P ) ≤ ε. By the choice of ε, S admits a noncrossing covering tree and a partition of its edges into segments such that 2s + t ≤ x. This contradicts the minimality of T , which completes the proof.
We conjecture that both problems, finding a noncrossing covering tree minimizing 2s + t for a given point set and finding a minimum perfect rainbow polygon for a given colored point set, are NP-complete. Many geometric variants of the classical set cover are known to be NP-hard. For example covering a finite set of points by the minimum number of lines is APXhard [13,28,31], see also [17,27]. The minimum-link covering problem (finding a covering path for a set of points with the smallest number of segments) is NP-complete [5]. However, in these problems, the covering objects (lines or edges) may cross. There are few results on covering points with noncrossing segments. It is known, for example, that it is NP-hard to find a maximum noncrossing matching in certain geometric graph [3]. The problem of, given an even number of points, finding a noncrossing matching that minimizes the length of the longest edge is also known to be NP-hard [2].
3 Rainbow indexes of k = 3, 4, 5, 6, 7 This section is devoted to determining the rainbow indexes rb-index(k) up to k = 7. The following theorem is the main result of this section, and it summarizes the results proven below.
Our proof for Theorem 5 relies on the following lemma (Lemma 6), which may be of independent interest. Lemma 6 guarantees the existence of a strip containing at least one point of each color, with the additional property that there are at least two color classes that have only one point in the strip.
Before proving the lemma, we introduce some notation. The line segment connecting two points x and y in the plane will be denoted by xy (or yx). Further, a ray emanating from x and passing through y is denoted by − → xy. Given two parallel lines 1 and 2 , defining a strip ST , we denote by ST the closure of the strip; that is, the set of points in the interior of the strip or on the lines 1 and 2 . Let A = conv(S 1 ) and B = conv(S − 3 ). We describe a sweepline algorithm in which we maintain a strip ST between two parallel lines 1 and 2 . Initially, 1 = L and 2 = U are horizontal lines. We also maintain the invariants that During the algorithm 1 rotates clockwise about the point in 1 ∩S 1 , and 2 rotates clockwise about the point 2 ∩ S − 3 , which are called the pivot points of 1 and 2 , respectively. Using a fully dynamic convex hull data structure [22], we maintain the convex hull of the points of S \ (A ∪ B) in ST , above 1 , and below 2 , respectively. By computing tangent lines from the two pivot points to the three convex hulls, we can maintain an event queue of when the next point in S \ (A ∪ B) enters or exits the strip ST (it is deleted from one convex hull and inserted into another) and when the pivot 1 ∩ S 1 or 2 ∩ S − 3 must be updated. We also maintain the Notice that if k = 3, then the strip defined by 1 and 2 in Lemma 6 is empty, so the triangle xyz is empty. As a consequence, Lemma 6 provides an alternative proof for rb-index(3) = 3.
x y z (a) In the remainder of this section, we refer to colors 1, 2, 3, 4, 5, 6, and 7 (if they exist) as red, blue, green, yellow, pink, orange, and black, respectively (e.g., a 4-colored point set will be red, blue, green, and yellow). Furthermore, when applying Lemma 6, we may assume withot loss of generality that the colors i 1 , i 2 , and i 3 are red, blue, and green, respectively, the lines 1 and 2 are horizontal, the point x is to the left of point y on 1 , and if 2 passes through another point w of S that is not green, then w is yellow. In addition, if p is the intersection point between a ray − → zu and a line , then p will denote a point infinitesimally close to p on the ray − → zu towards z; see Figure 3c.
Proof. We first show that rb-index(4) ≥ 4. Consider the 4-colored point set in Figure 3a, where S 1 = {x}, S 2 = {y}, S 3 = {z}, and S 4 consists of two points in the interior of the triangle xyz. Every triangle that contains a point of color 1, 2, and 3 must contain xyz, hence two points of S 4 . It follows that there exists no perfect rainbow triangle.
We now show that rb-index(4) ≤ 4. Let S = S 1 ∪ S 2 ∪ S 3 ∪ S 4 be a point set in the plane whose points are colored red, blue, green, and yellow. By Lemma 6, there is a strip defined by two horizontal lines, 1 and 2 , where 1 passes through a red point x and a blue point y, and 2 passes through a green point z, such that either there are only yellow points in the interior of the strip, or the strip is empty and 2 passes through a yellow point w. In the first case, we rotate the horizontal ray emanating from z clockwise until it encounters a yellow point u in the interior of the strip; see Figure 3b. Let p be the intersection point of − → zu and 1 . By symmetry, we may assume that p is to the left of x or on the segment xy. If p is to the left of x, then py ∪pz is a covering tree T for {x, y, z, u}, which can be thickened to a perfect rainbow quadrilateral by Lemma 1; see Figure 3b. If p is on xy, then yxzp is a perfect rainbow quadrilateral; see Figure 3c. Finally, if the strip is empty and 2 contains a yellow point w, then xyzw is a perfect rainbow quadrilateral.
Before moving to the next proposition, let us prove the following useful lemma that in fact works for monochromatic points. Proof. We first show that we can label the three points in P by a, b, c so that xya, yzb, and zxc are interior-disjoint. By symmetry, we may assume that the line passing through a and c intersects edges xy and xz of xyz, and a is closer to xy than c. Let p = − → ya ∩ − → zc. Since We say that the triangle rst described in Lemma 8 is expedient with respect to {a, b, c}. Note that an expedient triangle can be computed in O(1) time. Further, note that the labeling given in Lemma 8 is not unique, and thus expedient triangles are not uniquely determined. Using Lemma 8, one can find perfect rainbow hexagons for six colors in some special colored point sets, as the following lemma shows.  (Figure 5c), then r s t is an expedient triangle, where d lies on xr , a lies on ys , and b lies on zt . In all three cases, r s t ⊂ rst, as required.
Since r s t ⊂ rst, and since d ∈ rst and d ∈ r s t , it follows that r s t contains fewer points of S than rst. Hence we can repeat this procedure until we find an expedient triangle that is empty of points of S. From this expedient triangle, we can obtain a perfect rainbow hexagon for the six colors involved, by slightly moving the vertices of the expedient triangle towards the vertices of xyz as depicted in Figure 5d. Furthermore, an empty expedient triangle can be computed in O(n) time: We can start with an arbitrary expedient triangle rst. For each point s ∈ S, we can test whether s ∈ rst and update it to a smaller triangle r s t ⊂ rst if necessary in O(1) time. Consequently, a perfect rainbow polygon for six of the colors can also be found in O(n) time.
We are now ready to prove the following result.
The set S(5) consists of four one-element color classes S 1 = {x}, S 2 = {y}, S 3 = {z}, and s 4 = {w}, where w is in the interior of xyz. The set S 5 of black points contains xyz in its convex hull, as described in the proof of Theorem 4; that is, every triangle of area ε or more contains at least two black points; see Figure 6a. The set S(6) is obtained from S(5) by adding an one-element color class S 6 = {u}, where u is in the interior of xyz; see Figure 6b. The set S(7) is obtained from S(6) by adding a one-element color class S 7 = {v}, where v is in the interior of xyz, and the vertices u, v, and w are positioned such that − → xu crosses zw, − → zw crosses yv, and − → yv crosses xu; see Figure 6c. It is easy to see that a noncrossing covering tree for {x, y, z, w} in S(5), minimizing 2s + t, requires either two segments and a fork, or at least three segments (and no fork). Hence, by Theorem 4, the size of a minimum perfect polygon for S(5) is at least 5. Figure 6a illustrates a perfect rainbow pentagon based on a covering tree that uses a segment to cover x and z and another segment to cover y and w. Every noncrossing covering tree for {x, y, z, w, u} in S(6) requires at least three segments, so the size of any perfect rainbow polygon for S(6) is at least 6 by Theorem 4. Figure 6b shows a perfect rainbow hexagon based on three segments that cover x and u, y and w, and z, respectively.
Finally, consider a noncrossing covering tree for {x, y, z, w, u, v} in S (7). It has at least three segments, by the pigeonhole principle, since no three points are collinear. If it has four  Figure 6: 5-, 6-, and 7-colored points sets whose rainbow indices are 5, 6, and 8, respectively.
or more segments, then the size of the corresponding perfect rainbow polygon for S(7) is at least 8. Otherwise it consists of exactly three segments, and then an analysis of the possible choices shows that at least two forks are always required. Therefore, the size of a minimum perfect rainbow polygon for S(7) is at least 8. Figure 6c illustrates the perfect rainbow octagon for S(7) based on the segments that cover {x, u}, {y, v}, and {z, w}, respectively. We next show that rb-index(5) ≤ 5, rb-index(6) ≤ 6, and rb-index(7) ≤ 8. Let S be a k-colored point set in the plane, with k ∈ {5, 6, 7}. By Lemma 6, there is a strip defined by two horizontal lines 1 and 2 , with 1 passing through a red point x and a blue point y, and The strip ST contains points of all k − 3 other colors. Consider the horizontal ray emanating from z to the left and rotate it in clockwise direction, sweeping all the colored points in the strip until we find two consecutive points of S, say u and v, with different colors, say yellow and pink; see Figure 7a. Let p and q be the intersection points of − → zu and − → zv with 1 , respectively. Assume that p is to the left of x. If q is also to the left of x or on the line segment xy, then ypzq is a perfect rainbow quadrilateral for five of the colors; see Figure 7a. If q is to the right of y, then pqz is a perfect rainbow triangle for five of the colors; see Figure 7b. If k = 5, we are done. If k = 6, then we connect an orange point to z and thicken this edge (dotted line segments in Figures 7a and 7b). In this way, we obtain a perfect rainbow hexagon in the first case and a perfect rainbow pentagon in the second case. If k = 7, we repeat this process connecting a black point to z, to obtain either a perfect rainbow octagon or a perfect rainbow heptagon.
Suppose now that p is to the right of x. Arguing in an analogous way when rotating the horizontal ray emanating from z to the right counterclockwise, if u and v are two consecutive points with different colors, then we may assume that the intersection point p 1 between 1 and − → zu is to the left of y. When this happens, p to the right of x and p 1 to the left of y, it is straightforward to see that xyz must contain at least one point of each color, and that q is on xy. If k = 5, then yxp zq is a perfect rainbow pentagon; see Figure 7c. If k = 6, a perfect rainbow hexagon exists by Lemma 9; see Figure 5d. If k = 7, we can build a perfect rainbow hexagon for six of the colors by Lemma 9, and form a perfect rainbow octagon for S by connecting a black point to z and thicken this edge. zw. In the first case, yxpwp is a perfect rainbow pentagon; see Figure 7d. In the second case yxzwp is a perfect rainbow pentagon; see Figure 7e. When k = 6 or k = 7, the strip contains points of at least two of the colors and we can argue as before, but now rotating clockwise about w instead of about z, to look for the first two consecutive points u and v with different colors, say pink and orange. If the intersection point p between − → wu and 1 is to the left of x, then we can build a perfect rainbow quadrilateral or a perfect rainbow triangle for five of the colors, as shown in Figures 7a and 7b. After that, we connect z (and a black point if k = 7) to w to form a perfect rainbow hexagon (or a perfect octagon if k = 7) for S; see Figure 7f.
Finally, if p is to the right of x, then there are points of at least two of the colors to the left of − → xw. Therefore, when rotating the horizontal ray emanating from x to the right clockwise until finding two consecutive points u and v of different colors, the intersection point between − → xu and 2 will be necessarily to the right of w, and we can carry out symmetric constructions.
The following corollary is straightforward from the proofs of Propositions 7 and 10.
Corollary 11. For k = 3, 4, 5, 6, 7, a perfect rainbow polygon with at most rb-index(k) vertices can be found in O(n log n) time for any k-colored set S of n points.
Proof. By Lemma 6, the strip ST used in the proofs of Propositions 7 and 10 can be found in O(n log n) time. In addition, the cyclic order of the points in S around any of x, y, z or w can be computed in O(n log n) time. A perfect rainbow hexagon as described in Lemma 9 can be obtained in O(n) time. Therefore, the corollary follows.

Upper bound for rainbow indexes
We show in this section that for every k-colored point set, there exists a perfect rainbow polygon of size at most 10 k 7 + 11. We begin with an auxiliary lemma showing that any seven (monochromatic) points in a vertical strip can be covered by a noncrossing forest of two trees of order four and two, respectively, such that both trees are fully contained in the strip. (ii) For i ∈ {1, 2}, the tree T i has a leaf v i such that the ray emanating from v i in the direction opposite to the edge incident to v i does not cross T i . Moreover, if the extension at v i hits T j , j = i, then the extension at v j does not hit T i ; that is, the two trees and the two extensions do not create cycles.
Proof. Let be the line passing through p 1 and p 7 . Without loss of generality, we may assume that S contains at least 5/2 = 3 points below . Note that p 1 and p 7 are extremal points in S, hence they are vertices of the convex hull conv(S) of S. Points p 1 and p 7 decompose the boundary of conv(S) into two convex arcs, an upper arc and a lower arc. Since S contains at least 3 points below , the lower arc must have at least 3 vertices (including p 1 and p 7 ). We distinguish between two cases depending on the number of vertices of the lower arc of conv(S).
The lower arc of conv(S) has 3 vertices. Assume that the lower arc of conv(S) is the path (p 1 , p i , p 7 ), where 1 < i < 7; see Figures 8a-8b. Since S contains at least 3 points below , at least 2 points of S are in the interior of p 1 p i p 7 . Rotate the ray − − → p 1 p i counterclockwise until it encounters a point p a in the interior of p 1 p i p 7 ; rotate the ray − − → p 7 p i clockwise until it encounters a point p b in the interior of p 1 p i p 7 . We distinguish between two cases depending on whether p a and p b are distinct.
In the first case, assume that p a = p b ; see Figure 8a. The rays − − → p 1 p a and − − → p 7 p b intersect in the interior of p 1 p i p 7 , at some point q. By construction, the remaining two points in S \ {p 1 , p i , p 7 , p a , p b } are above the path (p 1 , q, p 7 ), in a wedge bounded by − → qp 1 and − → qp 7 . This wedge is convex, hence it contains the line segment between the two points. Let T 1 be the star centered at q with edges p 1 q, p i q, and p 7 q; and let T 2 be the line segment spanned by the two points of S above (p 1 , q, p 7 ).
In the second case, assume that p a = p b ; see Figure 8b. Let r be the first point along the ray − − → p i p a such that the line segment p 1 r or p 7 r contains a point of S in the interior of p 1 p a p 7 . Denote this point by p c ∈ S. By construction, the remaining two points in S \ {p 1 , p i , p 7 , p a , p c } are above the path (p 1 , r, p 7 ), in a convex wedge bounded by − → rp 1 and − → rp 7 . Let T 1 be the star centered at r with edges p 1 r, p i r, and p 7 r, and let T 2 be the line segment spanned by the two points of S above (p 1 , r, p 7 ).
In both cases, T 1 ∪ T 2 covers all seven points in S, is in B, and is noncrossing, as required. Moreover, the second property of the lemma is clearly satisfied by choosing v 1 = p 1 and v 2 the leftmost point of T 2 .
The lower arc of conv(S) has 4 or more vertices. Let p 1 , p i , p j , p k be the first four vertices of the lower arc of conv(S) in counterclockwise order (possibly p k = p 7 ). Let q be the intersection point of the lines passing through p 1 and p i , and through p j and p k , respectively. Rotate the ray − − → p k p j clockwise until it encounters a point in S \ {p 1 , p i , p j , p k }, and denote it by p a , Let T 1 be the union of the path (p 1 , q, p k , p a ), and connect the two remaining points of S to define T 2 ; see Figure 8c. Note that T 1 ∪ T 2 covers all seven points in S, is in B, and is noncrossing, as required. Moreover, the second property of the lemma is clearly satisfied by choosing v 1 = p 1 and v 2 the leftmost point of T 2 .
Using Lemma 12, the following theorem provides a method to find noncrossing covering trees with few segments and forks.
Theorem 13. Let S be a finite set of n = 7j + r points in the plane in general position, with j ≥ 0 and 0 ≤ r ≤ 6. Then, in O(n log n) time, we can construct a noncrossing covering tree T consisting of 4 n 7 + 1 + r 2 segments and 2 n 7 + r 2 forks with multiplicity 1.
Proof. By rotating the point set if necessary, we may assume that the points in S have distinct x-coordinates. We assume first that n = 7j, for some integer j > 0. Figure 9 illustrates the method to obtain a noncrossing covering tree with 4 n 7 + 1 segments and 2 n 7 forks with multiplicity 1. We partition the n points from left to right into j groups G 1 , G 2 , . . . , G j of seven points each; see Figure 9a. We apply Lemma 12 to every group G i to cover the points in G i by two trees, consisting of 4 segments in total; see Figure 9b. In this way, we obtain a forest F formed by 2j trees with 4j segments. In addition, by the same lemma, every tree T i of F contains a special leaf v i that can be extended to the left without crossing T i .
We add a long vertical segment P to the left of the point set such that the extension of any tree T i of F at v i crosses P ; see Figure 9c. For every tree T i , we extend the edge incident to its special leaf v i to the left until the extension hits another tree, another extension, or P ; see Figure 9c. This is carried out exploring, for example, the special leaves from right to left. Thus, we join the 2j trees of F and the segment P to form an single component. This component is necessarily a noncrossing covering tree T with 4j + 1 segments and 2j forks with multiplicity 1, since all extensions go to the left without creating cycles. Therefore, there exists a noncrossing covering tree T consisting of 4 n 7 + 1 segments and 2 n 7 forks with multiplicity 1. Consider the case that n = 7j + r, where 1 ≤ r ≤ 6. Using the first 7j points from left to right, we proceed as before, and we build a noncrossing covering tree T with 4j + 1 segments and 2j forks with multiplicity 1. If j = 0, the previous step is not required. The last r points can be covered by connecting the point at position 7j + 1 to the following one, the point at position 7j + 3 to the following one, and so on. If the last point cannot be connected to the following one, we assign an small horizontal segment to it. In this way, we are covering the last r points with r 2 segments. These segments can be joined to T by extending their leftmost points. Therefore, we can obtain a noncrossing covering tree T consisting of 4 n 7 + 1 + r 2 segments and 2 n 7 + r 2 forks with multiplicity 1. It remains to show that the construction above can be implemented in O(n log n) time. We can sort the points in Notice that by construction, the minimum number of pairwise noncrossing segments into which T can be decomposed is precisely 4 n 7 + 1 + r 2 . As a consequence of this theorem, we can give an upper bound for the size of a perfect rainbow polygon.
Theorem 14. Let S be a k-colored set of n points in general position. Then a perfect rainbow polygon P of size at most 10 k 7 + 11 can be computed in O(n log n) time.
Proof. We choose a point of each color to define a point set S of cardinality k = 7j + r, with j ≥ 0 and 0 ≤ r ≤ 6. By Theorem 13, there is a noncrossing covering tree T for the point set S , consisting of 4 k 7 + 1 + r 2 segments and 2 k 7 + r 2 forks with multiplicity 1, and it can be computed in O(k log k) time. By Lemma 1, given a noncrossing covering tree T and a partition M of the edges into the minimum number s of pairwise noncrossing segments, for every ε > 0, there exists a simple polygon P with 2s + t vertices such that area(P ) ≤ ε and T lies in P , where t is the sum of the multiplicities of all forks in T . Thus, for every ε > 0, we can construct a simple polygon P with 2(4 k 7 + 1 + r 2 ) + 2 k 7 + r 2 ≤ 10 k 7 + 11 vertices such that area(P ) ≤ ε and S lies in P . By choosing ε sufficiently small so that P contains no other point in S except for the points in S , we can construct a perfect rainbow polygon for S of size at most 10 k 7 + 11. A suitable ε > 0 can be half of the minimum distance between the covering tree T and the points in S \ S . To find this distance, we can compute the Voronoi diagram for a set of sites, which consists of the O(k) ≤ O(n) edges of T and the O(n) points in S \ S in O(n log n) time [14,Sec. 7.3]. The Voronoi diagram is formed by O(n) line segments and parabolic arcs; and we can find the closest point in T (hence in S \ S ) for each of these arcs in O(1) time.

Lower bound for rainbow indexes
For every k ≥ 3, Dumitrescu et al. [16] constructed a set S of n = 2k points in the plane (without colors) such that every noncrossing covering path has at least (5n−4)/9 edges. They also showed that every noncrossing covering tree for S has at least (9n − 4)/17 edges. Furthermore, every set of n ≥ 5 points in general position in the plane admits a noncrossing covering tree with at most n/2 noncrossing segments, and this bound is the best possible. We recall that a segment is defined as a chain of collinear edges.
In this section, we use the point sets constructed in [16] to derive a lower bound for the complexity of a covering tree as defined in Section 2. This bound, in turn, yields a lower bound on the complexity of perfect rainbow polygons for colored point sets built from such sets.
Construction. We use the point set constructed by Dumitrescu et al. [16]. We review some of its properties here. For every k ∈ N, they construct a set of n = 2k points, S = {a i , b i : i = 1, . . . , k}. The pairs {a i , b i } (i = 1, . . . , k) are called twins. The points a i (i = 1, . . . , k) lie on the parabola α = {(x, y) : y = x 2 }, sorted by increasing x-coordinate. The points b i (i = 1, . . . , k) lie on a convex curve β above α, such that dist(a i , b i ) < ε for a sufficiently small ε, and the lines a i b i are almost vertical with monotonically decreasing positive slopes (hence the supporting lines of any two twins intersect below α). For i = 1, . . . , k, they also define pairwise disjoint disks D i (ε) of radius ε centered at a i such that b i ∈ D i (ε), and the supporting lines of segments a i a j and b i b j meet in D i (ε) for every j, i < j ≤ k. Furthermore, (1) no three points in S are collinear; (2) no two lines determined by the points in S are parallel; and (3) no three lines determined by disjoint pairs of points in S are concurrent. Finally, the x-coordinates of a i (i = 1, . . . , k) are chosen such that (4) for any four points c 1 , c 2 , c 3 , c 4 from S, labeled by increasing x-coordinate, the supporting lines of c 1 c 4 and c 2 c 3 cross to the left of these points. See Figure 10 for a sketch of the construction.
Analysis. Let S be a set of n = 2k points defined in [16] as described above, for some k > 1. Let M be a set of pairwise noncrossing line segments in the plane whose union is connected and contains S. In particular, if T is a noncrossing covering tree for S, then any partition of the edges of T into pairwise noncrossing segments could be taken to be M.
A segment in M is called perfect if it contains two points in S; otherwise it is imperfect. By perturbing the endpoints of the segments in M, if necessary, we may assume that every point in S lies in the relative interior of a segment in M. By the construction of S, no three perfect segments are concurrent, so we can define the set Γ of maximal chains of perfect segments; we call these perfect chains.
Dumitrescu et al. [16, proved several properties of a covering path for S. Clearly, a covering path has precisely two leaves, while a covering tree may have arbitrarily Proof. Suppose, for the sake of contradiction, that γ 1 , γ 2 ∈ Γ x have a common right endpoint q. Let pq and rq, respectively, be the rightmost segments of γ 1 and γ 2 .
If pq contains a twin, then pq has positive slope (by construction), and so q is the upper endpoint of pq. In this case segment rq is imperfect by Lemma 16, contradicting the assumption that rq is in γ 2 . We may assume that neither pq not rq contains a twin. In this case, their supporting lines intersect to the left of the points in S on pq and pr by property (4), contradicting our assumption that q is the right endpoint of both segments.
Corollary 18. Every chain in Γ consists of at most two chains in Γ x .
Denote by s 0 , s 1 and s 2 , respectively, the number of segments in M that contain 0, 1, and 2 points from S. An adaptation of a charging scheme from [16,Lemma 4] yields the following result, where t is the number of forks (with multiplicity) in M.
Proof. Let pq be a perfect segment of M, and part of a chain γ ∈ Γ. We charge pq to either an endpoint of γ or some imperfect segment.
We define the charging as follows. If pq contains a twin, then charge pq to the top vertex of pq, which is the endpoint of a perfect chain by Lemma 16. Assume now that pq does not contain a twin, its left endpoint is p, and it contains a point from each of the twins {a i , b i } and {a j , b j }, with i < j. We consider the four cases presented in Lemma 15.
In Case 1, charge pq to p, which is the endpoint of a perfect chain. In Case 2, charge pq to the imperfect segment s containing a point of the twin {a i , b i }. In Case 3, charge pq to the endpoint v of a perfect chain located in D i (ε). Now, consider Case 4 of Lemma 15. In this case, pq is the leftmost segment of a maximal x-monotone chain γ x . We charge pq to the right endpoint of γ x , which is the endpoint of a perfect chain. This completes the definition of the charges.
Note that every imperfect segment and every right endpoint of a chain in Γ is charged at most once for perfect segments in Cases 1-3, and every left endpoint of a chain is charged at most twice. By Corollary 18, each endpoint of a perfect chain is charged at most once for perfect segments in Case 4. Overall, every imperfect segment containing one point of S is charged at most once, and every endpoint of a perfect chain is charged at most twice. Consequently, We bound |Γ| from above in terms of s 0 , s 2 , and t. Choose an arbitrary root vertex in T , and direct all edges in T towards the root. Every perfect chain has a unique vertex v closest to the root. As all chains in Γ are maximal and as no three prefect segments are concurrent, v must be a fork, the endpoint of an imperfect segment, or the root. This yields |Γ| ≤ 2(s 0 + s 1 ) + t + 1. Combined with (2), this yields, s 2 ≤ s 1 + 4[2(s 0 + s 1 ) + t + 1] = 8s 0 + 9s 1 + 4(t + 1), as claimed.
Theorem 21. For every integer k ≥ 5, there exists a finite set of k-colored points in the plane such that every perfect rainbow polygon has at least 40 (k−1)/2 −8 Proof. Assume first that k is odd, and let S be the set of k − 1 = 2j ≥ 4 points from [16]. If T is a noncrossing covering tree for S minimizing 2s + t = m, then by Theorem 4, there exists a k-colored point set S built from S such that every perfect rainbow polygon for S has at least m vertices. By Lemma 20, every noncrossing covering tree of S satisfies 2s + t ≥ 20(k−1)−8 19 , hence every perfect rainbow polygon for S has at least 20(k−1)−8 19 = 40 (k−1)/2 −8 19 vertices. Assume now that k is even. From the (k − 1)-colored point set S built previously, we can obtain a k-colored point set S by adding a new point with a different color. Since every perfect rainbow polygon for S has at least 20(k−2)−8 19 = 40 (k−1)/2 −8 19 vertices, then every perfect rainbow polygon for S also has at least 40 (k−1)/2 −8 19 vertices.

Conclusions
In this paper, we studied the perfect rainbow polygon problem and we proved that the rainbow index of k satisfies 40 (k−1)/2 −8

19
≤ rb-index(k) ≤ 10 k 7 + 11, for k ≥ 5. We also showed that k = 7 is the first value such that rb-index(k) = k. Our bounds are based on the equivalence between perfect rainbow polygons and noncrossing covering trees.
Several open questions arise in relation to this problem. For instance, we conjecture that given a colored point set S, finding a minimum perfect rainbow polygon for S is NP-complete. Another interesting question is to close the gap between the lower and upper bounds on the rainbow index.