Flip Distance to some Plane Configurations
Abstract
We study an old geometric optimization problem in the plane. Given a perfect matching on a set of points in the plane, we can transform it to a noncrossing perfect matching by a finite sequence of flip operations. The flip operation removes two crossing edges from and adds two noncrossing edges. Let and denote the minimum and maximum lengths of a flip sequence on , respectively. It has been proved by Bonnet and Miltzow (2016) that and by van Leeuwen and Schoone (1980) that . We prove that where is the spread of the point set, which is defined as the ratio between the longest and the shortest pairwise distances. This improves the previous bound if the point set has sublinear spread. For a matching on points in convex position we prove that and ; these bounds are tight.
Any bound on carries over to the bichromatic setting, while this is not necessarily true for . Let be a bichromatic matching. The best known upper bound for is the same as for , which is essentially . We prove that for points in convex position, and for semicollinear points.
The flip operation can also be defined on spanning trees. For a spanning tree on a convex point set we show that .
1 Introduction
A geometric graph is a graph whose vertices are points in the plane, and whose edges are straightline segments connecting the points. All graphs that we consider in this paper are geometric. A graph is plane if no pair of its edges cross each other. Let be an even integer, and let be a set of points in the plane that is in general position (no three points on a line). For two points and in the plane, we denote by the segment with endpoints and . Let be a perfect matching on . If two edges in cross each other, we can remove this crossing by a flip operation. The flip operation (or flip for short) removes two crossing edges and adds two noncrossing edges to obtain a new perfect matching. In other words, if two segments and cross, then a flip removes and from the matching, and adds either and , or and to the matching; see Figure 1(a). Every flip decreases the total length of the edges of , and thus, after a finite sequence of flips, can be transformed to a plane perfect matching. This process of transforming a crossing matching to a plane matching is referred to as uncrossing or untangling a matching. Motivated by this old folklore result, we investigate the minimum and the maximum lengths of a sequence of flips to reach a plane matching.
To uncross a perfect matching , we say that the sequence is a valid flip sequence if is obtained from by a single flip, and is plane. The number denotes the length of this flip sequence. We define to be the minimum length of any valid flip sequence to uncross , that is, the minimum number of flips required to transform to a plane perfect matching. We define to be the maximum length of any valid flip sequence. As for , one can imagine that an adversary imposes which of the two flips to apply on which of the crossings.
In the bichromatic setting, we are given red and blue points and a bichromatic matching, that is a perfect matching in which the two endpoints of every segment have distinct colors. Contrary to the monochromatic setting, there is only one way to flip two crossing bichromatic edges; see Figure 1(b). In the bichromatic setting the adversary can only impose the crossing to flip. Thus, any upper bound on for monochromatic matchings carries over to bichromatic matchings; this statement is not necessarily true for .
The flip operation can be defined for a spanning tree (resp. a Hamiltonian cycle) analogously, that is, we remove a pair of crossing edges and add two other edges so that the graph remains a spanning tree (resp. a Hamiltonian cycle) after this operation. We define and for spanning trees and Hamiltonian cycles, analogously. As shown in Figure 1(c), there is only one way to flip a crossing in a spanning tree (resp. a Hamiltonian cycle). Contrary to the bichromatic matching, it is not always possible to flip a crossing in a bichromatic spanning tree nor in a bichromatic Hamiltonian cycle; see Figure 1(d).
1.1 Related Work
The most relevant works are by van Leeuwen and Schoone [21], and Oda and Watanabe [17] for Hamiltonian cycles, and by Bonnet and Miltzow [7] for matchings. They proved, with elegant arguments, the following results.
Theorem 1 (van Leeuwen and Schoone, 1981 [21]).
For every Hamiltonian cycle on points in the plane we have that .
Theorem 2 (Oda and Watanabe, 2007 [17]).
For every Hamiltonian cycle on points in the plane in convex position we have that .
As for a lower bound, they presented a Hamiltonian cycle on points in the plane in convex position for which .
Theorem 3 (Bonnet and Miltzow, 2016 [7]).
For every perfect matching on a set of points in the plane in general position we have that .
The upper bound of Theorem 1 carries over to perfect matchings. As for lower bounds, Bonnet and Miltzow [7] presented two matchings and such that and . The bound holds even if is a bichromatic matching, while the proof of does not generalize for the bichromatic setting.
An alternate definition of an edge flip in a graph is the operation of removing one edge and inserting a different edge such that the resulting graph remains in the same graph class. The problem of minimizing the number of edge flips, to transform a graph into another, has been studied for many different graph classes. See the survey by Bose and Hurtado [8] on edge flips in planar graphs both in the combinatorial and the geometric settings, and see [3, 9, 14, 16] for edge flips in triangulations.
A related problem is the compatible matching problem in which we are given two perfect matchings on the same point set and the goal is to transform one to another by a sequence of compatible matchings (two perfect matchings, on the same point set, are said to be compatible if they are edge disjoint and their union is noncrossing). See [1, 2, 4, 15] for recent work on compatible matchings, and [18] for its extension to compatible trees.
1.2 Our Contribution
In this paper we decrease the gap between lower and upper bounds for and for some input configurations. In Section 2 we show that for every perfect matching , on a set of points in the plane, we have where is the spread of .
Assume that is in convex position. In Section 3 we show that for every perfect matching on we have that and . These bounds are tight as Bonnet and Miltzow [7] showed the existence of two perfect matchings and on points in convex position such that and . We also prove that for every spanning tree on we have that .
In Section 4 we study bichromatic matchings on special point sets. Assume that the points of are colored red and blue. We prove that, if is in convex position, then for every perfect bichromatic matching on we have that . Also, we prove that, if is semicollinear, i.e., the blue points are on a straight line, then for every perfect bichromatic matching on we have that . Table 1 summarizes the results.
1.3 Preliminaries
Let and be two points in the plane. We denote by the straight linesegment between and , and by the line through and . Let be a set of points in the plane in convex position. For two points and in we define the depth of the segment as the minimum number of points of on either side of . A boundary edge is a segment of depth zero, i.e., an edge of the convex hull of . An edge in a graph is said to be free if is not crossed by other edges of .
2 Minimum Number of Flips
The spread of a set of points (also called the distance ratio [11]) is the ratio between the largest and the smallest interpoint distances. It is well known that the spread of a set of points in the plane is (see e.g., [19]). In this section, we prove an upper bound on the minimum length of a flip sequence in terms of and . In fact we prove the following theorem.
Theorem 4.
For every perfect matching on a set of points in the plane in general position we have that , where is the spread of the point set.
For point sets with spread , the upper bound of Theorem 4 is better than the upper bound of Theorem 3. For example, for dense point sets, which have spread , Theorem 4 gives an upper bound of on the number of flips. According to [13], dense point sets commonly appear in nature, and they have applications in computer graphics. Valtr and others [13, 19, 20] have established several combinatorial bounds for dense point sets that improve corresponding bounds for arbitrary point sets.
Let be a set of points in the plane with spread . Let be a perfect matching on . We prove that can be untangled by flips, i.e., . The main idea of our proof is as follows. Let be the minimum distance between any pair of points in . Let denote the Euclidean distance between two points . Since has spread , we have For the matching we define its weight, , to be the total length of its edges. Since has edges,
(1) 
Recall that a pair of crossing segments can be flipped in two different ways as depicted in Figure 1(a). In the remainder of this section we show that one of these two flip operations reduces by at least , for some constant . Combining this with Equality (1) implies the existence of a flip sequence of length that uncrosses .
Take any two crossing edges and in , and let be their intersection point. We flip and to and , if , and to and , otherwise. In other words, we flip and to the two edges that face the two smaller angles at . In Lemma 3 we prove that this flip reduces the length of edges by at least , where is the minimum distance between any pair of points in . Since the minimum distance between pairs in is at least the minimum distance between pairs in , our result follows. We use the following two lemmas in the proof of Lemma 3; we prove these two lemmas later.
Lemma 1.
Let and be two crossing segments, and let be their intersection point. Let be the minimum distance between any pair of points in . If , then
Lemma 2.
Let and be two perpendicular segments that cross each other. Let be the minimum distance between any pair of points in . Then,
Lemma 3.
Let and be two crossing segments, and let be their intersection point. Let be the minimum distance between any pair of points in . If , then
Proof.
If , then our claim follows from Lemma 1 where play the roles of , respectively. Assume that . Observe that .
After a suitable rotation and/or a horizontal reflection and/or relabeling assume that , is horizontal, is to the left of , and lies above . Rotate counterclockwise about , while keeping on this segment, until is vertical. See Figure 2(a). After this rotation, let and denote the two points that correspond to and , respectively.
Claim . and .
We prove only the first inequality of this claim; the proof of the second inequality is analogous. Since is the hypotenuse of the right triangle , we have . Since is isosceles and , we have , and thus, . By the triangle inequality we have , which implies . This proves Claim 1.
Observe that , , , and by Claim 1, and . Thus, the minimum distance between any pair of points in is not smaller than half the minimum distance between any pair of points in , i.e., . By Lemma 2 we have , where play the roles of , respectively. Combining these inequalities, we get
∎
Note 1. The constants and in the proofs of Lemmas 2 and 3 are not optimized. To keep our proofs short and simple, we avoid optimizing these constants.
Note 2. The angle constraint in the statement of Lemma 3 cannot be dropped; the figure to the right shows two crossing segments and for which tends to zero as tends to .
Proof of Lemma 1.
We recall the simple fact that the largest side of every triangle always faces the largest angle of the triangle. Since , we have that or . Without loss of generality assume that , and thus, ; see Figure 2(b). This implies that . By a similar reasoning, we get that or . If , then
and if , then
Proof of Lemma 2.
Refer to Figure 2(c) for an illustration of the proof. Let be the intersection point of and . Let be the intersection point between and the line through that is perpendicular to . Without loss of generality assume that is longer than , i.e., . Then , and thus, . Since and , we get that is the smallest angle in the triangle , and thus, is its smallest side. Based on this and the fact that is a right triangle, we have
which implies that .
Let be the intersection point between and the line through that is perpendicular to . We consider two cases depending on which of and is longer.

: By a similar reasoning as for and we get that . Observe that and . By combining these inequalities we get

: Again, by a similar reasoning as for and we get that . Also, by a similar reasoning as in the previous case we get
∎
3 Points in Convex Position
In this section we study the problem of uncrossing perfect matchings and spanning trees on points in convex position. For perfect matchings, Bonnet and Miltzow [7] exhibited two perfect matchings and on points in the plane in convex position such that and . The following theorem provides matching upper bounds for and .
Theorem 5.
For every perfect matching on a set of points in the plane in convex position we have and .
Proof.
The matching contains edges. First we prove that . Notice that the number of crossings between the edges of is at most . We show that any flip reduces this number by at least one, and thus, our claim follows. Take any pair and of crossing edges of . Flip this crossing, and let and be the new edges, after a suitable relabeling. After this flip operation, the crossing between and disappears. Moreover, any edge of that crosses (or ) used to cross or , and any edge of that crosses both and used to cross both and . Therefore, the total number of crossings reduces by at least one, and thus, our claim follows.
Now, we prove, by induction on , that . If , then has only one edge, and thus, . Assume that . First, we show how to transform , by at most one flip, to a perfect matching containing a boundary edge, i.e., an edge of the boundary of the convex hull. Let be the points in clockwise order. Let be an edge of with minimum depth . If , then is a matching in which is a boundary edge. Suppose that . Without loss of generality assume that and . Let be the point that is matched to by . Because of the minimality of , the edge crosses . By flipping and to and we obtain in which is a boundary edge. Let be the matching on points obtaining from by removing a boundary edge. By the induction hypothesis, it holds that
In the rest of this section we study spanning trees. The argument of [21] for Hamiltonian cycles also extends to spanning trees, that is, if is a spanning tree on points in the plane, then . Also, by an argument similar to the one in the proof of Theorem 5, it can easily be shown that for every spanning tree on points in the plane in convex position we have that . In this section we prove that . Recall that a boundary edge is an edge of the boundary of the convex hull.
Lemma 4.
Any spanning tree on a point set in convex position can be transformed, by at most two flips, into a spanning tree containing a boundary edge.
Proof.
Let be a spanning tree on points in the plane in convex position, and let be the points in clockwise order. Let be an edge of with minimum depth (recall the definition of depth from Section 1.3). If , then is a boundary edge. Suppose that . Without loss of generality assume that and . Because of the minimality of , all edges of that are incident on cross . We consider two cases with and .

. In this case and . Let be the path between to in , and let be the vertex that is adjacent to in . If contains , then we flip and to and ; this gives a spanning tree in which is a boundary edge. If does not contain , then we flip and to and ; this gives a spanning tree in which is a boundary edge.

. Let be the path between to in , and let be the vertex that is adjacent to in . If contains , then we flip and to and ; this gives the a spanning tree in which is a boundary edge. Assume that does not contain . Let be the path between and in , and let be the vertex that is adjacent to in ; it may be that . If contains , then we flip and to and ; this gives a spanning tree in which is a boundary edge. Assume that does not contain . See Figure 3(a). In this case we have that , because otherwise would have a cycle. First we flip and to and , then we flip and to and ; this gives a spanning tree in which is a boundary edge. ∎
For the following lemma we do not need the vertices to be in convex position.
Lemma 5.
Let be a spanning tree containing an edge such that every other edge is incident on either or . Then , and this bound is tight.
Proof.
After a suitable rotation and/or a horizontal reflection and/or relabeling assume that is horizontal, is to the left of , and that . The edges that are incident on points above do not cross the edges incident on points below . Thus, the crossings above can be handled independently of the ones below . Because of symmetry, we describe how to handle the crossings above . See Figure 3(b). We show how to increase, by one flip, the number of free edges that are incident on . By repeating this process, our claim follows. To that end, let be the first vertex, in counterclockwise order, that is adjacent to , and such that is crossed by at least one edge incident on . Let be the first vertex, in counterclockwise order, that is adjacent to , and such that crosses ; see Figure 3(b). Flip this crossing to obtain new edges and . The edge is free, because otherwise cannot be the first counterclockwise edge that crosses . Moreover, any edge that is crossed by used to be crossed by . Thus, the number of free edges that are incident on increases by at least one. Notice that a flip operation does not change the degrees of vertices. Therefore, by repeating this process, after at most iterations, all incident edges on become free (notice that the edge is already free); this transforms to a plane spanning tree. This proves the first statement of the lemma.
Recall that the statement of this lemma is not restricted to points in convex position, and thus, the vertices of our tight example do not need to be in convex position. To verify the tightness of the bound, consider a tree in which every edge incident on (except ) is crossed by exactly one of the edges incident on , and every edge incident on crosses at most one of the edges incident on . This tree needs exactly flips to be transformed to a plane tree. ∎
Theorem 6.
For every spanning tree on points in the plane in convex position we have that .
Proof.
We present a recursive algorithm that uncrosses by flips. As for the base case, if , then is plane, and thus, no flip is needed. Assume that . By Lemma 4, by at most two flips, we can transform to a tree containing a boundary edge . Contract the edge and denote the resulting tree with vertices by ; this can be done by removing the vertex together with its incident edges, and then connecting its neighbors, by straightline edges, to . We call every such new edge a edge. Recursively uncross with flips. During the uncrossing process of , whenever we flip/remove a edge, we call the new edge that gets connected to a edge. After uncrossing we return the vertex back and connect it to . Then we remove every edge , which is incident on , and connect to . In the resulting tree, every crossing is between an edge that is incident on and an edge that is incident on . Thus, after at most flips, can be transformed into a tree in which any two crossing edges are incident on and . Then by Lemma 5, we can obtain a plane tree by performing at most more flips. Notice that the flip operation does not change the degree of vertices, and thus, every vertex in the resulting tree has the same degree as in . Therefore, we have that
It remains to show that . To that end, we interpret the above recursion by a unionfind data structure with the linkedlist representation and the weightedunion heuristic [12, Chapter 21]. The number of flips in the above recursion can be interpreted as the total time for union operations as follows: each time that we contract an edge and recurse on a smaller tree we perform at most flips. Consider every vertex of as a set with elements. Also, assume that all the elements of these sets are pairwise distinct. Thus, we have disjoint sets of total size ; this is coming from the fact that has edges and its total vertex degree is . The contraction of an edge can be interpreted as a union operation of the sets and whose cost (number of flips) is at most , where denotes the size of the set . From the unionfind data structure we have that the cost of a sequence of operations on elements is . In our case, the number of elements is , and the number of union operations (edge contractions) is (no contraction is needed when we hit the base case). Thus, it follows that the total cost (the total number of flips) is . ∎
4 Bichromatic Matchings
In this section we study the problem of uncrossing perfect bichromatic matchings for points in convex position and for semicollinear points. Let be an even integer, and let be a set of points in the plane, of which are colored red and are colored blue. If is in general position, then for any bichromatic matching on , the best known upper bound for both and is the bound that has been proved in [7, 21]. If is in convex position, the and lower bounds that are shown in [7] for and , respectively, in the monochromatic setting, also hold in the bichromatic setting. Theorem 5 implies that the bound for is tight. The following theorem gives an upper bound on for points in convex position.
Theorem 7.
For every perfect bichromatic matching on points in the plane in convex position we have that .
Proof.
Our proof is by induction on . If , then . Assume that . First we show how to transform , by at most two flips, to a perfect bichromatic matching containing a boundary edge. Let be the points in clockwise order. Let be an edge of with minimum depth . If , then is a matching in which is a boundary edge. Suppose that . Without loss of generality assume that , , is red, and is blue as in Figure 4. Let and be the points that are matched to and , respectively; it may be that and . Because of the minimality of , all edges that are incident on points cross . If is blue, then by flipping and to and we obtain in which is a boundary edge. Assume that is red. If is red, then by flipping and to and we obtain in which is a boundary edge. Assume that is blue. See Figure 4. It follows that and have different colors, and thus, and .
For an illustration of the rest of the proof, follow Figure 4. The sequence starts with a red point and ends with a blue point. Thus, in this sequence there are two points of distinct colors, say and , that are consecutive. Let be the first blue point after . Let and be the two points that are matched to and respectively. By flipping and to and , and then flipping and to and we obtain in which is a boundary edge.
Let be the bichromatic matching on points obtaining from by removing a boundary edge. By the induction hypothesis, it holds that
In the rest of this section we study the case where is semicollinear, i.e., its blue points are on a straight line and its red points are in general position. Semicollinear points have been studied in may problems related to plane matchings (see e.g., [5, 6, 10]). We prove that for every perfect bichromatic matching on , it holds that . Before we prove this upper bound, observe that similar to the general position setting, in the semicollinear setting the total number of crossings might increase after a flip. Also, it is possible that a crossing, that has disappeared after a flip, reappears after some more flips (see the crossing between and in Figure 5). The upper bound given in [7] for on uncolored points, which is obtained by connecting the two leftmost points of a crossing, does not apply to our semicollinear bichromatic setting, because in this setting the two leftmost points might have the same color. These observations suggest that there is no straightforward way of getting a good upper bound.
Let be the line that contains all the blue points of . By a suitable rotation we assume that is horizontal. For every perfect bichromatic matching on , the edges of , that are above , do not cross the ones that are below . Thus, we can handle these two sets of edges independently of each other. Therefore, in the rest of this section we assume that the red points of lie above . Recall that contains blue points and red points.
Lemma 6.
Let be a perfect bichromatic matching on in which the rightmost blue point is matched to the topmost red point . If is plane, then , and this bound is tight.
Proof.
See Figure 6(a) for an illustration of the statement of this lemma; notice that if we remove from , then we get a plane matching. Our proof is by induction on . If , then has one edge which is plane, and thus, . Assume that . If does not intersect any other edge, then is plane and . Suppose that intersects some edges of , and let be the set of the red endpoints of those edges; see Figure 6(a). Let be the first red point in the counterclockwise order of the red points around ; observe that belongs to . Let be the blue point that is matched to . Flip and to and as in Figure 6(b), and let be the resulting matching. The edge does not cross any other edge of , because of our choice of , but the edge may cross some edges of . Let be the subset of edges of that are to the left of ; see Figure 6(b). Notice that , and thus is a matching on at most points.
Because of the planarity of and since is the topmost red point, we have that is plane. Moreover, and are separated by . Observe that is the rightmost blue point in that is matched to the topmost red point , moreover, is plane. Therefore, we can repeat the above process on , which is a smaller instance of the initial problem. By the induction hypothesis, it holds that
To verify the tightness, Figure 6(c) shows a matching example for which we need exactly flips to transform it to a plane matching. Each time there exists exactly one crossing, and after flipping that crossing, only one other crossing appears (except for the last flip). ∎
Theorem 8.
For every perfect bichromatic matching on we have .
Proof.
We present an iterative algorithm that uncrosses by flips. Let be the blue points from left to right. By a suitable relabeling assume that . To simplify the description of the proof, we add, to , a dummy edge such that is a blue point on that is to the left of all the blue points, is a red point that is higher than all the red points, and all points of are to the right of .
We describe one iteration of our algorithm. If is plane, then the algorithm terminates. Assume that is not plane. Let be the smallest index such that intersects some edges of ; see Figure 7left. To simplify the rest of our description, we refer to the current iteration as iteration . Notice that the blue endpoint of every nonfree edge is strictly to the right of . We perform the following walk along the edges of and stop as soon as we meet a red point. Starting from , we walk along until we see the first edge, say , that crosses . Then we turn left on and keep walking until we see another edge, say , that crosses . Then we turn left on and continue this process until we meet a red point for the first time. Let denote this red point and let be the blue point that is matched to . Let be the sequence of edges visited along this walk, and denote the convex polygonal path that we have traversed; see Figure 7left.
We are going to use to connect with by at most flips in such a way that none of the new edges intersects (except which will connect the two endpoints of ). Observe that the blue points are ordered from left to right. We repeatedly flip the edge incident to until we connect with . To that end, we first flip and (which are crossing) to and . The edge is to the right of . If , then the edge intersects some other edge such that and . In this case we flip and to . The edge is to the right of ; in Figure 7left we have and . Then we repeat this process with until gets connected to . It turns out that after every flip, connects to a blue point that is closer to , and the other edge is to the right of . Therefore after at most flips we get the edge . Since , the total number of flips in the above process is at most .
Let be the matching obtained after the above process. See Figure 7right. Shoot a horizontal ray from , to the left, and stop as soon as it hits an edge in with (the dummy edge ensures that such an index exists). Let be the subset of the edges of that are incident on , that is,