I'm just asking because I'm curious.
I was seeking references on the following problem, that a friend exposed to me last holidays :


Problem
-------


Given $n$ red points and $n$ blue points in the plane in general position (no 3 of them are aligned), find a pairing of the red points with the blue points such that the segments it draws are all disjoint.


This problem is always solvable, and admits several proof. A proof I know goes like this :


Start with an arbitrary pairing, and look for intersections of the segments it defines, if there are none you're done. If you found one, do the following operation :



```
r   r         r   r
 \ /          |   |
  X     =>    |   |
 / \          |   |
b   b         b   b

```

(uncross the crossing you have found), you may create new crossings with this operation. If you repeat this operation, you cannot cycle, because the triangle inequality shows that the sum of the length of the segments is strictly decreasing. So you will eventually get stuck at a configuration with no crossings.


Questions
---------


1. What is the complexity of the algorithm described in the proof ?
2. What is the best known algorithm to solve this problem ?


I wouldn't be surprised to learn that this problem is a classic in computational geometry, however googling didn't give me references. Since some computational geometers are active on MO, I thought I could get interesting answers here.



Complexity of matching red and blue points in the plane.
The Ghosts and Ghostbusters problem can be solved in $O(n\log n)$ time, which is considerably faster than the $O(n^2\log n)$-time algorithm suggested by CLRS.


The [ham sandwich theorem](https://en.wikipedia.org/wiki/Ham_sandwich_theorem) implies that there is a line $L$ that splits both the ghosts and the ghostbusters exactly in half. (If the number of ghosts and ghostbusters is odd, the line passes through one of each; if the number is even, the line passes through neither.) Lo, Matoušek, and Steiger [[*Discrete Comput. Geom.* 1994](https://doi.org/10.1007/BF02574017)] describe an algorithm to compute a ham-sandwich line in $O(n)$ time; their algorithm is also sketched [here](https://web.archive.org/web/20160804011140/http://www.tcs.fudan.edu.cn/rudolf/Courses/Algorithms/Alg_cs_07w/Webprojects/Jiajin_redblue/ham-linear.html). Now recursively solve the problem on both sides of $L$; the recursion stops when all subsets are empty. The total running time obeys the mergesort recurrence $T(n) = O(n) + 2T(n/2)$ and thus is $O(n\log n)$.


This algorithm is optimal in the [algebraic decision tree and algebraic computation tree models of computation](http://www.cs.uiuc.edu/%7Ejeffe/teaching/497/06-algebraic-tree.pdf), because you need $\Omega(n\log n)$ time in those models just to decide whether two sets of $n$ points are equal.


