Flip Distance to some Plane Configurations

We study an old geometric optimization problem in the plane. Given a perfect matching $M$ on a set of $n$ points in the plane, we can transform it to a non-crossing perfect matching by a finite sequence of flip operations. The flip operation removes two crossing edges from $M$ and adds two non-crossing edges. Let $f(M)$ and $F(M)$ denote the minimum and maximum lengths of a flip sequence on $M$, respectively. It has been proved by Bonnet and Miltzow (2016) that $f(M)=O(n^2)$ and by van Leeuwen and Schoone (1980) that $F(M)=O(n^3)$. We prove that $f(M)=O(n\Delta)$ where $\Delta$ 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 $M$ on $n$ points in convex position we prove that $f(M)=n/2-1$ and $F(M)={{n/2} \choose 2}$; these bounds are tight. Any bound on $F(\cdot)$ carries over to the bichromatic setting, while this is not necessarily true for $f(\cdot)$. Let $M'$ be a bichromatic matching. The best known upper bound for $f(M')$ is the same as for $F(M')$, which is essentially $O(n^3)$. We prove that $f(M')\le n-2$ for points in convex position, and $f(M')= O(n^2)$ for semi-collinear points. The flip operation can also be defined on spanning trees. For a spanning tree $T$ on a convex point set we show that $f(T)=O(n\log n)$.


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 n 2 be an even integer, and let P be a set of n points in the plane that is in general position (no three points on a line). For two points a and b in the plane, we denote by ab the segment with endpoints a and b. Let M be a perfect matching on P . If two edges in M 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 non-crossing edges to obtain a new perfect matching. In other words, if two segments ab and cd cross, then a flip removes ab and cd from the matching, and adds either ac and bd, or ad and bc to the matching; see Figure 1(a). Every flip decreases the total length of the edges of M , and thus, after a finite sequence of flips, M 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 M , we say that the sequence (M =M 0 , M 1 , . . . , M k ) is a valid flip sequence if M i+1 is obtained from M i by a single flip, and M k is plane. The number k denotes the length of this flip sequence. We define f (M ) to be the minimum length of any valid flip sequence to uncross M , that is, the minimum number of flips required to transform M to a plane perfect matching. We define F (M ) to be the maximum length of any valid flip sequence. As for F (M ), 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 n/2 red and n/2 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 F (M ) for monochromatic matchings carries over to bichromatic matchings; this statement is not necessarily true for f (M ). 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 f (·) and F (·) 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).

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 H on n points in the plane we have that F (H) = O(n 3 ).
Theorem 2 (Oda and Watanabe, 2007 [17]). For every Hamiltonian cycle H on n points in the plane in convex position we have that f (H) 2n − 7.
As for a lower bound, they presented a Hamiltonian cycle H on n 7 points in the plane in convex position for which f (H) n − 2.  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 non-crossing). See [1,2,4,15] for recent work on compatible matchings, and [18] for its extension to compatible trees.

Our Contribution
In this paper we decrease the gap between lower and upper bounds for f (·) and F (·) for some input configurations. In Section 2 we show that for every perfect matching M , on a set P of n points in the plane, we have f (M ) = O(n∆) where ∆ is the spread of P .
Assume that P is in convex position. In Section 3 we show that for every perfect matching M on P we have that f (M ) n/2 − 1 and F (M ) n/2 2 . These bounds are tight as Bonnet and Miltzow [7] showed the existence of two perfect matchings M 1 and M 2 on n points in convex position such that f (M 1 ) n/2 − 1 and F (M 2 ) n/2 2 . We also prove that for every spanning tree T on P we have that f (T ) = O(n log n).
In Section 4 we study bichromatic matchings on special point sets. Assume that the points of P are colored red and blue. We prove that, if P is in convex position, then for every perfect bichromatic matching M on P we have that f (M ) n − 2. Also, we prove that, if P is semicollinear, i.e., the blue points are on a straight line, then for every perfect bichromatic matching M on P we have that f (M ) = O(n 2 ). Table 1 summarizes the results.

Preliminaries
Let a and b be two points in the plane. We denote by ab the straight line-segment between a and b, and by ab the line through a and b. Let P be a set of points in the plane in convex position. For two points p and q in P we define the depth of the segment pq as the minimum number of points of P \ {p, q} on either side of pq. A boundary edge is a segment of depth zero, i.e., an edge of the convex hull of P . An edge e in a graph G is said to be free if e is not crossed by other edges of G.

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 n points in the plane is Ω( √ n) (see e.g., [19]). In this section, we prove an upper bound on the minimum length of a flip sequence in terms of n and ∆. In fact we prove the following theorem.  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 P be a set of n points in the plane with spread ∆. Let M be a perfect matching on P . We prove that M can be untangled by O(n∆) flips, i.e., f (M ) = O(n∆). The main idea of our proof is as follows. Let µ be the minimum distance between any pair of points in P . Let |pq| denote the Euclidean distance between two points p, q ∈ P . Since P has spread ∆, we have |pq| µ∆. For the matching M we define its weight, w(M ), to be the total length of its edges. Since M has n/2 edges, 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 w(M ) by at least tµ, for some constant t > 0. Combining this with Equality (1) implies the existence of a flip sequence of length O(n∆) that uncrosses M .
Take any two crossing edges pq and rs in M , and let o be their intersection point. We flip pq and rs to ps and rq, if ∠roq π/2, and to pr and qs, otherwise. In other words, we flip pq and rs to the two edges that face the two smaller angles at o. In Lemma 3 we prove that this flip reduces the length of edges by at least 2− √ 2 4 µ , where µ is the minimum distance between any pair of points in {p, q, r, s}. Since the minimum distance between pairs in {p, q, r, s} is at least the minimum distance between pairs in P , our result follows. We use the following two lemmas in the proof of Lemma 3; we prove these two lemmas later. Lemma 1. Let ab and cd be two crossing segments, and let o be their intersection point. Let µ be the minimum distance between any pair of points in {a, b, c, d}. If ∠cob π/3, then (|ab| + |cd|) − (|ad| + |cb|) µ .

Lemma 2.
Let ab and cd be two perpendicular segments that cross each other. Let µ be the minimum distance between any pair of points in {a, b, c, d}. Then, Lemma 3. Let pq and rs be two crossing segments, and let o be their intersection point. Let µ be the minimum distance between any pair of points in {p, q, r, s}. If ∠roq π/2, then Proof. If ∠roq < π/3, then our claim follows from Lemma 1 where p, q, r, s play the roles of a, b, c, d, respectively. Assume that ∠roq π/3. Observe that ∠roq = ∠pos. After a suitable rotation and/or a horizontal reflection and/or relabeling assume that |pq| |rs|, pq is horizontal, p is to the left of q, and r lies above pq. Rotate rs counterclockwise about o, while keeping o on this segment, until rs is vertical. See Figure 2(a). After this rotation, let r and s denote the two points that correspond to r and s, respectively. Claim 1. |r p| > |rp|/2 and |qs | > |qs|/2.
We prove only the first inequality of this claim; the proof of the second inequality is analogous. Since r p is the hypotenuse of the right triangle r op, we have |r o| |r p|. Since r or is isosceles and ∠r or π/6, we have |rr | < |r o|, and thus, |rr | < |r p|. By the triangle inequality we have |rp| |rr | + |r p| < 2|r p|, which implies |r p| > |rp|/2. This proves Claim 1.
Observe that |r q| |rq|, |ps | |ps|, |r s | = |rs|, and by Claim 1, |r p| |rp|/2 and |qs | |qs|/2. Thus, the minimum distance µ between any pair of points in {p, q, r , s } is not smaller than half the minimum distance between any pair of points in {p, q, r, s}, i.e., µ µ /2. By Lemma 2 we have (|pq| + |r s |) − (|ps | + |r q|) 2− √ 2 2 µ , where p, q, r , s play the roles of a, b, c, d, respectively. Combining these inequalities, we get µ . in the proofs of Lemmas 2 and 3 are not optimized. To keep our proofs short and simple, we avoid optimizing these constants. p q r s o Note 2. The angle constraint in the statement of Lemma 3 cannot be dropped; the figure to the right shows two crossing segments pq and rs for which (|pq| + |rs|) − (|ps| + |rq|) tends to zero as ∠roq 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 ∠cob π/3, we have that ∠cbo π/3 or ∠bco π/3. Without loss of generality assume that ∠bco π/3, and thus, ∠bco ∠cob; see Figure 2(b). This implies that |ob| |cb|. By a similar reasoning, we get that |oa| |ad| or |od| |ad|. If |oa| |ad|, then and if |od| |ad|, then Proof of Lemma 2. Refer to Figure 2(c) for an illustration of the proof. Let o be the intersection point of ab and cd. Let o be the intersection point between cb and the line through o that is perpendicular to cb. Without loss of generality assume that ob is longer than oc, i.e., |ob| |oc|. Then ∠ocb ∠obc, and thus, ∠ocb π/4. Since ∠oo c = π/2 and ∠oco = ∠ocb π/4, we get that ∠coo is the smallest angle in the triangle oco , and thus, o c is its smallest side. Based on this and the fact that coo is a right triangle, we have which implies that |o c| |oc|/ √ 2. Let o be the intersection point between ad and the line through o that is perpendicular to ad. We consider two cases depending on which of oa and od is longer.
• |oa| |od|: Again, by a similar reasoning as for ob and oc we get that |o a| |oa|/ √ 2. Also, by a similar reasoning as in the previous case we get µ .

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 M 1 and M 2 on n points in the plane in convex position such that f (M 1 ) n/2 − 1 and F (M 2 ) n/2 2 . The following theorem provides matching upper bounds for f (·) and F (·). Proof. The matching M contains n/2 edges. First we prove that F (M ) Notice that the number of crossings between the edges of M is at most n/2 2 . We show that any flip reduces this number by at least one, and thus, our claim follows. Take any pair ab and cd of crossing edges of M . Flip this crossing, and let ac and bd be the new edges, after a suitable relabeling. After this flip operation, the crossing between ab and cd disappears. Moreover, any edge of M that crosses ac (or bd) used to cross ab or cd, and any edge of M that crosses both ac and bd used to cross both ab and cd. Therefore, the total number of crossings reduces by at least one, and thus, our claim follows. Now, we prove, by induction on n, that f (M ) n/2 − 1. If n = 2, then M has only one edge, and thus, f (M ) = 0. Assume that n 4. First, we show how to transform M , by at most one flip, to a perfect matching M containing a boundary edge, i.e., an edge of the boundary of the convex hull. Let p 1 , . . . , p n be the points in clockwise order. Let p i p j be an edge of M with minimum depth m. If m = 0, then M = M is a matching in which p i p j is a boundary edge. Suppose that m 1. Without loss of generality assume that i = 1 and j = m + 2. Let p k be the point that is matched to p 2 by M . Because of the minimality of m, the edge p 2 p k crosses p 1 p m+2 . By flipping p 2 p k and p 1 p m+2 to p 1 p 2 and p m+2 p k we obtain M in which p 1 p 2 is a boundary edge. Let M be the matching on n − 2 points obtaining from M 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 T 1 is a spanning tree on n points in the plane, then F (T 1 ) = O(n 3 ). Also, by an argument similar to the one in the proof of Theorem 5, it can easily be shown that for every spanning tree T on n points in the plane in convex position we have that F (T ) = O(n 2 ). In this section we prove that f (T ) = O(n log n). Recall that a boundary edge is an edge of the boundary of the convex hull. Proof. Let T be a spanning tree on n points in the plane in convex position, and let p 1 , . . . , p n be the points in clockwise order. Let p i p j be an edge of T with minimum depth m (recall the definition of depth from Section 1.3). If m = 0, then p i p j is a boundary edge. Suppose that m 1. Without loss of generality assume that i = 1 and j = m + 2. Because of the minimality of m, all edges of T that are incident on p 2 , . . . , p m+1 cross p 1 p m+2 . We consider two cases with m = 1 and m > 1.
• m = 1. In this case p m+1 = p 2 and p m+2 = p 3 . Let δ be the path between p 2 to p 3 in T , and let p k be the vertex that is adjacent to p 2 in δ. If δ contains p 1 , then we flip p 1 p 3 and p 2 p k to p 1 p 2 and p 3 p k ; this gives a spanning tree in which p 1 p 2 is a boundary edge. If δ does not contain p 1 , then we flip p 1 p 3 and p 2 p k to p 2 p 3 and p 1 p k ; this gives a spanning tree in which p 2 p 3 is a boundary edge.
• m > 1. Let δ be the path between p 2 to p m+2 in T , and let p k be the vertex that is adjacent to p 2 in δ. If δ contains p 1 , then we flip p 1 p m+2 and p 2 p k to p 1 p 2 and p m+2 p k ; this gives the a spanning tree in which p 1 p 2 is a boundary edge. Assume that δ does not contain p 1 . Let δ be the path between p m+1 and p 1 in T , and let p k be the vertex that is adjacent to p m+1 in δ ; it may be that k = k. If δ contains p m+2 , then we flip p 1 p m+2 and p m+1 p k to p m+1 p m+2 and p 1 p k ; this gives a spanning tree in which p m+1 p m+2 is a boundary edge. Assume that δ does not contain p m+2 . See Figure 3(a). In this case we have that k = k, because otherwise T would have a cycle. First we flip p 1 p m+2 and p m+1 p k to p 1 p m+1 and p m+2 p k , then we flip p 1 p m+1 and p 2 p k to p 1 p 2 and p k p m+1 ; this gives a spanning tree in which p 1 p 2 is a boundary edge. Figure 3: (a) Illustration of the proof of Lemma 4: Flipping p 1 p m+2 and p m+1 p k to p 1 p m+1 and p m+2 p k , and then flipping p 1 p m+1 and p 2 p k to p 1 p 2 and p k p m+1 . (b) Illustration of the proof of Lemma 5: vv is the first counterclockwise edge incident on v that is crossed by some edges incident on u, and uu is the first counterclockwise edge incident on u that crosses vv .
For the following lemma we do not need the vertices to be in convex position.
Lemma 5. Let T be a spanning tree containing an edge uv such that every other edge is incident on either u or v. Then f (T ) min(deg (u), deg (v)) − 1, and this bound is tight.
Proof. After a suitable rotation and/or a horizontal reflection and/or relabeling assume that uv is horizontal, u is to the left of v, and that deg (v) deg (u). The edges that are incident on points above uv do not cross the edges incident on points below uv. Thus, the crossings above uv can be handled independently of the ones below uv. Because of symmetry, we describe how to handle the crossings above uv. See Figure 3(b). We show how to increase, by one flip, the number of free edges that are incident on v. By repeating this process, our claim follows. To that end, let v be the first vertex, in counterclockwise order, that is adjacent to v, and such that vv is crossed by at least one edge incident on u. Let u be the first vertex, in counterclockwise order, that is adjacent to u, and such that uu crosses vv ; see Figure 3(b). Flip this crossing to obtain new edges vu and uv . The edge vu is free, because otherwise uu cannot be the first counterclockwise edge that crosses vv . Moreover, any edge that is crossed by uv used to be crossed by uu . Thus, the number of free edges that are incident on v 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 deg (v) − 1 iterations, all incident edges on v become free (notice that the edge uv is already free); this transforms T 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 v (except uv) is crossed by exactly one of the edges incident on u, and every edge incident on u crosses at most one of the edges incident on v. This tree needs exactly deg (v) − 1 flips to be transformed to a plane tree.
Theorem 6. For every spanning tree T on n points in the plane in convex position we have that f (T ) = O(n log n).
Proof. We present a recursive algorithm that uncrosses T by O(n log n) flips. As for the base case, if n 3, then T is plane, and thus, no flip is needed. Assume that n 4. By Lemma 4, by at most two flips, we can transform T to a tree T containing a boundary edge uv. Contract the edge uv and denote the resulting tree with n − 1 vertices by T ; this can be done by removing the vertex u together with its incident edges, and then connecting its neighbors, by straight-line edges, to v. We call every such new edge a u-edge. Recursively uncross T with f (T ) flips. During the uncrossing process of T , whenever we flip/remove a u-edge, we call the new edge that gets connected to v a u-edge. After uncrossing T we return the vertex u back and connect it to v. Then we remove every u-edge vv , which is incident on v, and connect v to u. In the resulting tree, every crossing is between an edge that is incident on u and an edge that is incident on v. Thus, after at most 2 + f (T ) flips, T can be transformed into a tree in which any two crossing edges are incident on u and v. Then by Lemma 5, we can obtain a plane tree by performing at most min(deg(u), deg(v))−1 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 T . Therefore, we have that It remains to show that f (T ) = O(n log n). To that end, we interpret the above recursion by a union-find data structure with the linked-list representation and the weighted-union 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 uv and recurse on a smaller tree we perform at most 1 + min(deg (u), deg (v)) flips. Consider every vertex x of T as a set with deg (x) elements. Also, assume that all the elements of these sets are pairwise distinct. Thus, we have n disjoint sets of total size 2(n − 1); this is coming from the fact that T has n − 1 edges and its total vertex degree is 2(n − 1). The contraction of an edge uv can be interpreted as a union operation of the sets u and v whose cost (number of flips) is at most 1 + min(|u|, |v|), where |x| denotes the size of the set x. From the union-find data structure we have that the cost of a sequence of s operations on m elements is O(s + m log m). In our case, the number m of elements is 2(n − 1), and the number s of union operations (edge contractions) is n − 3 (no contraction is needed when we hit the base case). Thus, it follows that the total cost (the total number of flips) is O(n log n).

Bichromatic Matchings
In this section we study the problem of uncrossing perfect bichromatic matchings for points in convex position and for semi-collinear points. Let n 2 be an even integer, and let P be a set of n points in the plane, n/2 of which are colored red and n/2 are colored blue. If P is in general position, then for any bichromatic matching M on P , the best known upper bound for both f (M ) and F (M ) is the O(n 3 ) bound that has been proved in [7,21]. If P is in convex position, the n/2−1 and n/2 2 lower bounds that are shown in [7] for f (·) and F (·), respectively, in the monochromatic setting, also hold in the bichromatic setting. Theorem 5 implies that the n/2 2 bound for F (·) is tight. The following theorem gives an upper bound on f (·) for points in convex position. Figure 4: Illustration of the proof of Theorem 7. Flipping bb and p 1 p m+2 to b p m+2 and bp , and then flipping bp 1 and aa to p 1 a and ab. Proof. Our proof is by induction on n. If n = 2, then f (M ) = 0. Assume that n 4. First we show how to transform M , by at most two flips, to a perfect bichromatic matching M containing a boundary edge. Let p 1 , . . . , p n be the points in clockwise order. Let p i p j be an edge of M with minimum depth m. If m = 0, then M = M is a matching in which p i p j is a boundary edge. Suppose that m 1. Without loss of generality assume that i = 1, j = m + 2, p 1 is red, and p m+2 is blue as in Figure 4. Let p k and p k be the points that are matched to p 2 and p m+1 , respectively; it may be that m + 1 = 2 and k = k. Because of the minimality of m, all edges that are incident on points p 2 , . . . , p m+1 cross p 1 p m+2 . If p 2 is blue, then by flipping p 1 p m+2 and p 2 p k to p 1 p 2 and p m+2 p k we obtain M in which p 1 p 2 is a boundary edge. Assume that p 2 is red. If p m+1 is red, then by flipping p 1 p m+2 and p m+1 p k to p m+1 p m+2 and p 1 p k we obtain M in which p m+1 p m+2 is a boundary edge. Assume that p m+1 is blue. See Figure 4. It follows that p 2 and p m+1 have different colors, and thus, m + 1 = 2 and k = k.
For an illustration of the rest of the proof, follow Figure 4. The sequence p 2 , . . . , p m+1 starts with a red point and ends with a blue point. Thus, in this sequence there are two points of distinct colors, say a and b, that are consecutive. Let b be the first blue point after p 1 . Let a and b be the two points that are matched to a and b respectively. By flipping bb and p 1 p m+2 to b p m+2 and bp 1 , and then flipping bp 1 and aa to p 1 a and ab we obtain M in which ab is a boundary edge.
Let M be the bichromatic matching on n−2 points obtaining from M by removing a boundary edge. By the induction hypothesis, it holds that In the rest of this section we study the case where P is semi-collinear, i.e., its blue points are on a straight line and its red points are in general position. Semi-collinear 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 M on P , it holds that f (M ) = O(n 2 ). Before we prove this upper bound, observe that similar to the general position setting, in the semi-collinear 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 br and b r in Figure 5). The O(n 2 ) upper bound given in [7] for f (·) on uncolored points, which is obtained by connecting the two leftmost points of a crossing, does not apply to our semi-collinear 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 P . By a suitable rotation we assume that is horizontal. For every perfect bichromatic matching M on P , the edges of M , 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 P lie above . Recall that P contains n/2 blue points and n/2 red points. Observe that b is the rightmost blue point in M that is matched to the topmost red point r, moreover, M \ {b r} is plane. Therefore, we can repeat the above process on M , 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 n/2−1 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). Figure 7: Illustration of the proof of Theorem 8. From the left configuration, we will get to the right configuration by flipping the following crossing pairs: (r j b j , r l 2 b l 2 ), (r j b l 2 , r l 1 b l 2 ), and (r j b l 1 , r i b i ). Proof. We present an iterative algorithm that uncrosses M by O(n 2 ) flips. Let b 1 , . . . , b n/2 be the blue points from left to right. By a suitable relabeling assume that M = {b 1 r 1 , . . . , b n/2 r n/2 }. To simplify the description of the proof, we add, to M , a dummy edge b 0 r 0 such that b 0 is a blue point on that is to the left of all the blue points, r 0 is a red point that is higher than all the red points, and all points of P are to the right of b 0 r 0 . We describe one iteration of our algorithm. If M is plane, then the algorithm terminates. Assume that M is not plane. Let i ∈ {1, . . . , n/2} be the smallest index such that b i r i intersects some edges of M ; see Figure 7-left. To simplify the rest of our description, we refer to the current iteration as iteration i. Notice that the blue endpoint of every non-free edge is strictly to the right of b i−1 . We perform the following walk along the edges of M and stop as soon as we meet a red point. Starting from b i , we walk along b i r i until we see the first edge, say b l 1 r l 1 , that crosses b i r i . Then we turn left on b l 1 r l 1 and keep walking until we see another edge, say b l 2 r l 2 , that crosses b l 1 r l 1 . Then we turn left on b l 2 r l 2 and continue this process until we meet a red point for the first time. Let r j denote this red point and let b j be the blue point that is matched to r j . Let δ = b i r i , b l 1 r l 1 , b l 2 r l 2 , . . . , b l k r l k , b j r j be the sequence of edges visited along this walk, and w denote the convex polygonal path that we have traversed; see Figure 7-left.
We are going to use δ to connect r j with b i by at most j − i flips in such a way that none of the new edges intersects w (except r j b i which will connect the two endpoints of w). Observe that the blue points b i , b l 1 , b l 2 , . . . , b l k , b j are ordered from left to right. We repeatedly flip the edge incident to r j until we connect r j with b i . To that end, we first flip r j b j and r l k b l k (which are crossing) to r j b l k and r l k b j . The edge r l k b j is to the right of w. If b l k = b i , then the edge r j b l k intersects some other edge r l k b l k such that r l k b l k ∈ δ and k < k. In this case we flip r j b l k and r l k b l k to r j b l k r l k b l k . The edge r l k b l k is to the right of w; in Figure 7-left we have k = 2 and k = 1. Then we repeat this process with r j b l k until r j gets connected to b i . It turns out that after every flip, r j connects to a blue point that is closer to b i , and the other edge is to the right of w. Therefore after at most j − i flips we get the edge r j b i . Since j n/2, the total number of flips in the above process is at most n/2 − i.
Let M be the matching obtained after the above process. See Figure 7-right. Shoot a horizontal ray from r j , to the left, and stop as soon as it hits an edge b x r x in M with x ∈ {0, . . . , i − 1} (the dummy edge b 0 r 0 ensures that such an index x exists). Let M be the subset of the edges of M that are incident on b x+1 , . . . , b i , that is, M = {b x+1 r x+1 , . . . , b i−1 r i−1 , b i r j }. By our choices of r j and the flips in the above process, the edges of M are in a convex region whose interior is disjoint from the edges of M \ M ; this convex region is bounded by , b x r x , w, and the ray from r j , as depicted in Figure 7-right. The matching M has i − x edges. Observe that, in M , we have that b i is the rightmost blue point that is matched to the topmost red point r j , and M \ {b i r j } is plane. Thus, by Lemma 6 we can uncross M by at most i − x − 1 flips. To this end, we have transformed M to a matching in which the edges that are incident on b 1 , . . . , b i are free. The total number of flips performed in iteration i is at most (n/2 − i) + (i − x − 1) = n/2 − x − 1 n/2 − 1.
In the next iteration, the smallest index i , for which b i r i is not free, is larger than i. Thus, this smallest index moves at least one step to the right after each iteration. This means that the number of free edges, that are connected to the blue points of lower indices, increases. Therefore, after at most n/2 iterations our algorithm terminates. The total number of flips is

Conclusions
We investigated the number of flips that are necessary and sufficient to reach a non-crossing perfect matching on n points in the plane. It is known that the minimum and the maximum lengths of a flip sequence are O(n 2 ) and O(n 3 ), respectively. We proved, with a new approach, that the minimum length of a flip sequence is O(n∆) where ∆ is the spread of the points set; this improves the previous bound if the point set has sublinear spread. A natural open problem is to improve any of these bounds. Another open problem is to improve our O(n log n) upper bound on the number of sufficient flips to reach a plane spanning tree on points in convex position, or to show that this bound is tight. One potential way to do this, is that in Theorem 6, we get a boundary edge uv such that one of u or v has a constant degree. It is worth mentioning that the number of flips, in a flip sequence, is highly dependent on the order in which we choose crossings to flip, and the type of a flip that we perform (among the two possible types). This dependency can be used to improve the bounds on the minimum number of flips. In Theorems 5, 6, 7, and 8 we used the order and proved some upper bounds, while in Theorem 4 we used the flip type. One may think of using the order and the flip type together to improve the current bounds. Notice that for bichromatic matchings, spanning trees, and Hamiltonian cycles only one type of flip is possible, and thus, only the order can be used for further improvements. Also, notice that none of the order and the flip type can be used to improve the bounds on the maximum number of flips, because, in this case, an adversary chooses the order and the type.