Exact Subquadratic Algorithm for Many-To-Many Matching on Planar Point Sets with Integer Coordinates
Abstract
In this paper, we study the many-to-many matching problem on planar point sets with integer coordinates: Given two disjoint sets with , the goal is to select a set of edges between and so that every point is incident to at least one edge and the total Euclidean length is minimized. In the general case that and are point sets in the plane, the best-known algorithm for the many-to-many matching problem takes time. We present an exact time algorithm for point sets in . To the best of our knowledge, this is the first subquadratic exact algorithm for planar many-to-many matching under bounded integer coordinates.
Keywords and phrases:
Edge cover, many-to-many matching, similarity, geometric matchingCopyright and License:
2012 ACM Subject Classification:
Theory of computation Design and analysis of algorithms ; Theory of computation Computational geometryFunding:
Supported by Institute of Information & Communications Technology Planning & Evaluation (IITP) grant funded by the Korea government (MSIT) (No. RS-2024-00440239, Sublinear Scalable Algorithms for Large-Scale Data Analysis) and the National Research Foundation of Korea (NRF) grant funded by the Korea government (MSIT) (No. RS-2024-00358505).Editor:
Pierre FraigniaudSeries and Publisher:
Leibniz International Proceedings in Informatics, Schloss Dagstuhl – Leibniz-Zentrum für Informatik
1 Introduction
Measuring the similarity between two point sets is a fundamental problem in computational geometry and pattern recognition [1, 22, 23]. A widely used measure is the Earth Mover’s Distance (EMD), which captures the global distribution of point sets by finding an optimal correspondence [18, 19]. Formally, for two sets and of the same cardinality, the EMD is defined as the minimum cost of a perfect matching: , where is a bijection. While EMD is effective at preserving the holistic structure of the sets, its definition is inherently restricted to cases where . To accommodate sets of different cardinalities, one might consider pointwise heuristics such as the Chamfer distance: . It provides a simple way to handle unequal set sizes as it treats each connection independently and sums distances without any global coordination. However, this often fails to capture the underlying structural correspondence, as it lacks the “assignment” nature that makes EMD robust.
A more principled approach to handling different sized sets, instead of resorting to pointwise measures, is to generalize the matching framework of EMD itself. By relaxing the strict one-to-one matching requirement to a many-to-many correspondence, we arrive at the minimum link measure introduced by [7]. Formally, a many-to-many matching is a set of edges such that every point in is incident to at least one edge in . The cost is the total weight . The minimum link measure is the minimum cost of a many-to-many matching between and . This “setwise” approach preserves the global structural integrity of EMD by seeking an optimal set of edges that covers both sets simultaneously. As a single edge in can satisfy the coverage requirement for points in both and , the minimum link measure maintains a mutual correspondence that is more stable and geometrically intuitive than independent pointwise distances.
In this paper, we consider the problem of computing a minimum-cost many-to-many matching, also called the minimum link measure, between two point sets in Euclidean space. This problem was originally introduced by Eiter and Mannila [7]. While an efficient, optimal algorithm exists for points on a line, the problem becomes significantly more difficult in higher dimensions. Even for planar point sets, the best-known exact algorithm still suffers from a quadratic bottleneck [3], mirroring the challenges found in various other geometric bipartite matching problems [11]. To bridge this gap, we consider the case where the inputs lie on an integer grid as an intermediate step toward the general planar case.
Our results.
In this paper, we present the first subquadratic-time exact algorithm for the many-to-many matching problem for point sets on an integer grid. Our main result is summarized in the following theorem.
Theorem 1.
Given two disjoint sets111With a slight modification, we can deal with the non-disjoint case without increasing the running time. and of points in , we can compute a minimum-cost many-to-many matching between and in time,222The -notation hides polylogarithmic factors in . where .
A key technical challenge in achieving this bound is efficiently handling subproblems where points can be either matched to the opposite set or remain unmatched by paying a certain cost. To this end, we introduce the minimum-cost matching with penalties problem: Given two point sets and where each point is associated with a real-valued penalty , we seek a matching that minimizes , where denotes the set of points in not incident to any edge in . To the best of our knowledge, this problem has not been explicitly studied before. Although this can be solved in time via standard reductions to the minimum-cost perfect matching problem for bipartite graphs, the cubic-time algorithm is too slow for our purpose. As a subroutine for our main algorithm, we provide an optimal algorithm for this penalty variant in one dimension, which we believe is of independent interest, stated as follows.
Theorem 2.
Given two disjoint sets and of points on a real line, where each point has a real-valued penalty, a minimum-cost matching with penalties can be computed in time, where .
Related works.
The study of the minimum-cost many-to-many matching problem was introduced by Eiter and Mannila [7]. They established that the problem is solvable in time by reducing it to the minimum-cost perfect matching problem on graphs [7]. For the one-dimensional case where points lie on a real line, Colannino et al. [5] provided an optimal -time algorithm, improving upon previous results [6]. In the Euclidean plane, the best-known exact algorithm runs in time [3]. On the other hand, in higher dimensions, no non-trivial algorithm is known for this problem while an -time algorithm can be obtained easily by reducing it to a minimum-cost perfect matching of a graph of complexity. Given the challenge of computing exact solutions in subquadratic time, several approximation algorithms have been explored. The Chamfer distance serves as a simple -approximation for the many-to-many matching cost [3]. Furthermore, -approximate solutions can be computed in time for -dimensional Euclidean space, or any metric space with a constant doubling dimension [2, 4].
As EMD is a more classical setting, there are numerous results on computing the EMD between two points (also known as the minimum-cost perfect matching). By implementing the Hungarian algorithm [15] using a dynamic weighted nearest neighbor data structure [12], one can compute the exact EMD of two point sets in the plane in time [11]. While the exact bipartite matching problem in the plane suffers from a quadratic bottleneck, the problem becomes easier if there are constraints on the input points. For instance, if the points in and are drawn independently and identically from a fixed distribution that is not known to the algorithm, the exact EMD between and can be computed in time, where denotes the spread of (i.e, the ratio of the maximum distance to the minimum distance). If and come from , Sharathkumar [20] presented an -time algorithm.333The paper [20] states that their algorithm takes time for a constant , but by replacing a nearest neighbor data structure used in this paper with the most recent one [12], the factor can be replaced with .
2 Preliminaries and Algorithm Overview
In this section, we first describe an alternative view for the problem and then provide an overview of our algorithm. An alternative way is to view the many-to-many matching problem as a geometric graph problem. Consider a complete bipartite graph with vertex set and with edge set where the cost of an edge is the Euclidean distance between their endpoints. An edge cover of is a subset of such that every vertex of is incident to at least one edge of it. The cost of an edge cover of is defined as the sum of the costs of its edges. Then the many-to-many matching problem on and is equivalent to the problem of finding an edge cover of with the minimum cost.
For a general graph with vertices and edges, a minimum-cost edge cover can be solved in time via a reduction to the minimum-cost perfect matching [8, 9, 13]. Since the complete bipartite graph has complexity , we cannot use these graph algorithms directly to obtain a subquadratic-time algorithm. Nevertheless, as our approach extensively adapts several combinatorial principles from these classical algorithms, we introduce the following graph-theoretic terminology to be used throughout this paper.
Terminology for matching.
Let be a bipartite graph with edge costs. A matching in is a set of pairwise vertex-disjoint edges, and its cost defined as the sum of its edge costs. A matching in is perfect if every vertex is incident to exactly one edge of . A vertex of the graph is free (with respect to ) if no edge of is incident to it. An alternating path (with respect to ) is a path in the graph that begins from a free vertex and whose edges alternately belong to and not to . An augmenting path (with respect to ) is an alternating path whose two endpoints are both free. Augmenting along an augmenting path by taking symmetric difference () increases its cardinality by one. A matching has maximum cardinality if no augmenting path exists. Classically, maximum-cardinality (or minimum-cost) matchings are computed by repeatedly augmenting along paths with certain properties until none remain.
2.1 Reduction to the Min-Cost Perfect Matching
In this section, we describe a reduction from the minimum-cost many-to-many matching problem to the minimum-cost perfect matching problem. While this is identical to the folklore reduction, we refer to the resulting graph as the prism graph for notational convenience. It preserves the original geometric embedding and induces independent vertex penalties.
Let and be two point sets in , and let be the complete bipartite graph between and , where the cost of each edge is the Euclidean distance between its endpoints. The reduced instance is called the prism graph of , denoted by , with an associated edge cost .
Prism graph.
The prism graph is a two-layered bipartite graph consisting of an “upper” layer, which is the original graph , and a “lower” layer, which is a mirrored copy of . For each vertex in the upper layer, we add a link edge between and its corresponding copy in the lower layer. Note that remains bipartite, as its vertex set can be partitioned into and . See Figure 1. For an edge in , the cost is defined as follows:
-
If and are both in the upper layer, .
-
If and are both in the lower layer, .
-
If is a link edge , , where is the distance from to its nearest neighbor in the opposite set ( or ).
Note that an optimal edge cover of consists of disjoint stars. For a star of of size larger than two, let be the center of the star. Then for every vertex of the star other than , its closest neighbor in the opposite set is . Otherwise, we can reconnect it with its closest neighbor without violating the feasibility of the solution. This reduces the problem into the minimum-cost matching problem with penalties where the penalty of each point is . The construction of the prism graph is based on this intuition. Matching a vertex via a link edge to the lower layer simulates leaving that vertex uncovered by the primary matching in the upper layer, instead paying the penalty of connecting it to its nearest neighbor.
The values for all can be computed in time by constructing the Voronoi diagrams of and and using a planar point location data structure [14]. Although has edges in the worst case, we can store it using complexity of by maintaining only the vertices and the link edges explicitly. The edges in and can be represented implicitly as they form complete bipartite graphs.
The following lemma establishes the equivalence between the minimum-cost edge cover of and the minimum-cost perfect matching of . For illustration, see Figure 1.
Lemma 3 ([3]).
Given a minimum-cost perfect matching of , a minimum-cost edge cover of can be computed in time.
Due to the lack of space, some proofs are omitted. The missing proofs can be found in the full version of this paper.
2.2 Overview of Our Algorithm
Due to Lemma 3, the problem reduces to computing a minimum-cost perfect matching of . The algorithm consists of two phases.
In the first phase, we compute an approximate perfect matching of with its corresponding dual weights. We use the approximation algorithm of Bandyapadhyay et al. [3] which is based on the scaling algorithm [10], with dynamic additively weighted nearest-neighbor data structures [12] to obtain these dual weights in time.
In the second phase, we leverage these dual weights to construct a sparse candidate subgraph of containing an optimal perfect matching of . Here, a crucial property is that it is almost planar. Specifically, the upper layer of possesses a planar skeleton, meaning no two edges of cross unless their endpoints are collinear, and the lower layer of is a mirrored copy of its upper layer. We then compute the exact minimum-cost perfect matching of by applying a divide-and-conquer strategy on a balanced separator of this planar skeleton.
While this overall strategy comes from the subquadratic-time algorithm for the one-to-one setting on integer grids [20], we address two major technical hurdles unique to the many-to-many setting.
-
During the construction of and within the recursion step, we must efficiently solve subproblems where points can either be matched to the opposite set or left unmatched by paying a penalty. To handle this, we develop an -time algorithm for the 1D minimum-cost matching problem with penalties (Section 3), replacing the simple greedy approach used for standard 1D perfect matching.
-
In the one-to-one setting [20], the candidate graph is strictly planar, allowing direct application of the separator-based algorithm in [17]. In our case, is not strictly planar. We overcome this by applying the balanced separator exclusively to the planar skeleton of (Section 4.2). A tricky part is to handle the vertices of not appearing on the planar skeleton. We address this using their 1D nature: these vertices are fully contained in the open intervals (edges) of the planar skeleton, which allows us to process them efficiently using our 1D matching subroutine.
In the following, some proofs and details are omitted due to page limits. All missing proofs and details can be found in the full version of this paper.
3 Subroutine: 1D Minimum Cost Bipartite Matching with Penalties
In this section, we prove Theorem 2, that is, we present an -time algorithm for the 1D minimum-cost bipartite matching problem with penalties. As input, we are given two sets and lying on a horizontal line where each point is associated with a penalty . For a matching between and , its cost is defined as . That is, its cost is the total edge length of plus the total penalty of the unmatched vertices. The goal is to compute a matching between and of minimum total cost.
To the best of our knowledge, there is no work explicitly studying the minimum-cost bipartite matching problem with penalties even for the one-dimensional case. However, there are several ways to address this problem. First, this problem reduces to the min-cost flow problem on planar directed graphs. Also, if points of have integer coordinates, and the penalties are all integers, then the resulting instance has integer costs. In this case, we can solve the problem in time, where is the maximum of the maximum cost and the diameter of . However, the penalty can be an arbitrary real number in our case, which makes the aforementioned algorithm inapplicable in our setting. Another simple way is to use dynamic programming, which leads to an -time algorithm. Since our main algorithm is based on this dynamic programming algorithm, we also describe it here.
3.1 Quadratic-Time DP Algorithm
Let be the line containing and . Without loss of generality, assume that is horizontal. For a point , let and be the sets of points in and , respectively, lying to the left of (including the points lying on ). For any point and a positive integer , we let denote the minimum matching cost with penalties between and , where is the set obtained from by adding points at with penalty . For a negative integer , we let denote the minimum matching cost with penalties between and , where is the set obtained from by adding points at with penalty . Then the minimum matching cost between and is . Therefore, the problem reduces to computing for all points in and for all values with .
Lemma 4.
For any value and any two points and of such that no point of lies between and (including and ), we have .
Thus it is sufficient to compute for all points and all values . But to avoid a degeneracy issue, for each point , we compute for a conceptual point located infinitesimally to the right of . For all distance calculations, we treat . As initialization, let be any point lying strictly to the left of the first point in . Then and for any . Starting from this base case, we process the points of from left to right along . We show how to handle a point . Without loss of generality, assume that . The other case can be handled symmetrically. Let be the point of lying immediately to the left of along , and let . Then we have the following recurrence relation. There are two possibilities: either is matched with a blue point in , or is not used in the matching by paying the penalty. We consider both cases, and take the one with minimum cost.
| (1) |
The recurrence relation immediately shows how to compute for all points . Each table entry can be computed in time, yielding an overall running time of .
In the following, to make the description easier, we simply let as the following analysis is based only on the recurrence relation (1).
3.2 Convexity of the Cost Function
In this subsection, we show that the function is convex for any fixed point . We say is convex if for every integer . If or , the inequality holds immediately. We let be the set of integers such that is finite. Let .
Lemma 5.
The function is convex for any fixed point .
Proof.
We use induction on the points of encountered from left to right. Let be a point to the left of the leftmost point of . We define and for , which is trivially convex.
Let be the current point and be the previous point in . Let . Without loss of generality, assume that . By the induction hypothesis, is convex. Note that is a convex function of . Since the sum of two convex functions is also convex, is convex. Similarly, is convex. Although the minimum of two convex functions is not convex in general, it is convex in our setting. This holds due to the following claim with .
Claim 6.
Let be a convex function. Then is also convex for any value .
Therefore, the lemma holds for any fixed point .
As we showed in the proof of Claim 6, the following corollary holds.
Corollary 7.
Let be the largest integer with . Then for , we have , and for , we have .
3.3 Near-Linear-Time Algorithm
In this subsection, we present an -time algorithm for the 1D minimum-cost bipartite matching problem with penalties. For each , let be the maximal interval of integers for which . By the recurrence, is always a contiguous interval. Basically, we compute for all integers and all points . By maintaining using a data structure for a fixed , we show that can be computed in time for all integers for a fixed assuming that we have , where is the point of lying immediately to the left of .
Representation of the cost function.
Fix , and let . We maintain and for all indices . Note that they fully represent . To make the update efficiently, we store using two balanced binary search trees. Let and be two sets where
Since is convex, is non-decreasing with respect to . We maintain the two sets using two binary search trees and and offsets and . The offsets allow us to shift all stored values uniformly without updating each element explicitly. Each leaf of a tree of (and ) corresponds to exactly one index (and ), and the leaf stores the value (and ). Thus, the actual value of is obtained by adding the corresponding offset or . Each internal node additionally stores the size of its subtree and the sum of the stored values in its subtree (excluding the offset). Hence, the true sum of the values in any subtree can be obtained by adding the offset multiplied by the subtree size. The leaves of (and ) are stored in increasing order of their indices . Since is convex, the stored values are non-decreasing along this order. Therefore, and can be implemented as binary search trees augmented with subtree sizes and subtree sums, supporting insertion, deletion, and prefix-sum queries in time. We call the tuple of , , , and the representation of . Here, since the roots store the size of the trees, we do not need to explicitly maintain .
Observation 8.
Given the representation of , we can compute for any integer in time.
Proof.
We show how to compute for any integer . For , we maintain explicitly, and for , we can do this symmetrically. By telescoping, we have
Thus, it suffices to compute the prefix sum of the first values in .
Since is non-decreasing in , the values stored in are already ordered by index. We augment each node of with the size of its subtree and the sum of the stored values in its subtree (excluding the offset ). Using standard binary search tree operations, we can retrieve the sum of the smallest elements in in time. Adding this sum and the accumulated offset to yields . Therefore, given the representation of , we can compute for any integer in time.
Update of the representation.
Assume that we are given the representation of , and we wish to compute the representation of , where is the next point to the right of on . We describe the case ; the case is symmetric. Let .
Step 1.
We first consider the transportation cost. Let . Thus, before handling the matching/penalty decision at , we first transform the representation of into the representation of . For , we have , and for , we have . Hence, this update can be performed by increasing the offset by , and decreasing the offset by , while keeping the trees unchanged. Also, remains unchanged since . After this step, the representation corresponds to .
Step 2.
Step 3.
We now update the representation of to obtain that of . We first compute . Since , this value can be computed in time using Observation 8.
We next determine the new discrete derivatives. For , both and lie in the same case, and hence
For , we have
At the boundary , we have
Therefore, the sequence is obtained from by inserting the single value (minus the corresponding offset) at position . As a result, all indices strictly larger than are shifted by one position to the right.
Since the discrete derivatives are stored in a binary search tree, this transformation can be implemented by a single rank-based insertion at index . If , the insertion shifts the element originally at index to index . Because index belongs to and index belongs to , we must extract the maximum element from and insert it as the minimum element in (after adjusting the values with respect to the offsets for the two trees). All subtree sizes and subtree sums are updated along the search path. The insertion and any necessary boundary shifts take time. Thus, the entire update from the representation of to that of takes time.
Lemma 9.
Given the representation of , we can compute the representation of in time.
We consider the points of from left to right. The initialization takes time, and each update takes time. Therefore, the total running time is .
4 Minimum-Cost Perfect Matching for Prism Graphs
In this section, we present an exact algorithm for computing a minimum-cost perfect matching of the prism graph . To simplify the exposition, we identify the vertices in the upper layer of the prism graph directly with the original points in and . Specifically, we let the upper layer vertex set be . We then define the lower layer as a mirrored copy of the upper layer, where each vertex has a corresponding copy in the lower layer.
Our strategy involves two main phases: computing an approximate minimum-cost perfect matching of along with its associated dual weights, and utilizing these dual weights to derive the exact solution. We begin by establishing the properties of an approximate solution and the associated dual weights.
1-optimality.
Given a scaling factor , let denote the -scaled graph of with the edge-cost function , defined as for all . Let denote the dual weight of a vertex . A matching in and the associated dual weights are said to be 1-feasible if
| (2) | ||||
| (3) |
We refer to (2) and (3) as the 1-feasibility conditions. An edge is called admissible if . The admissible graph of is the subgraph of consisting of all admissible edges and the edges in . If a matching and dual weights satisfy the 1-feasibility conditions and is a perfect matching, we call the pair 1-optimal. Sharathkumar and Agarwal [21] showed that a 1-optimal matching of provides an approximate minimum-cost perfect matching of with an additive error of at most .
We now outline our algorithm for computing an exact minimum-cost perfect matching of . First, we compute a 1-optimal matching and associated dual weights of using a scaling factor of , following the procedure described in the full version of this paper. In Section 4.1, we utilize these dual weights to identify a set of eligible edges of the upper layer of and exploit their geometric properties to construct a set of non-crossing line segments having endpoints at . Using , we systematically extract a sparse candidate subgraph of size that is guaranteed to contain a minimum-cost perfect matching of . Finally, Section 4.2 presents a divide-and-conquer algorithm to compute an exact optimal solution in by applying the planar separator theorem to the graph induced by .
4.1 Construction of the Candidate Subgraph
We construct a candidate subgraph of that is guaranteed to contain an optimal matching of . We begin by utilizing the 1-optimal matching and the 1-optimal dual weights of with a scaling factor of to characterize the eligible edges in the upper layer that can participate in an optimal solution. This characterization reveals a crucial geometric property of these edges. Using this property, we apply the technique of Sharathkumar [20] to construct a planar skeleton (planar straight-line graph) . Finally, we use to generate the set of candidate edges .
The overall construction comes from Sharathkumar [20]: It applies the approach to a Euclidean complete bipartite graph while we apply it to the upper layer of the prism graph . As the upper layer is a Euclidean complete bipartite graph, the analysis immediately follows from [20], but the detailed implementation should be tailored for our setting.
Eligible edge decomposition and its induced planar skeleton.
We define the scaled dual weight of a vertex as . The following lemma establishes a lower bound on the sum of scaled dual weights for the edges participating in an optimal matching of .
Lemma 10.
Let be the scaled dual weights associated with a -optimal matching of using the scaling factor . Let be a minimum-cost perfect matching of . Then, for every edge in the upper layer,
| (4) |
The proof is same as the argument in [20] and is thus omitted. We define the set of eligible edges, denoted by , as the set of all edges in the upper layer of satisfying the condition (4). Lemma 10 implies that for any optimal matching of , all edges of that belong to the upper layer are contained in . Therefore, even if we remove all non-eligible edges in the upper layer from the prism graph, the optimal solution remains the same.
The following lemma shows that if no four vertices of are collinear, then the graph obtained from the upper layer of the prism graph by removing all non-eligible edges is planar. Thus our main focus is to handle collinear points in the following.
Lemma 11 ([20]).
Let be a set of points. Let be four distinct points that are not collinear. If the line segments and intersect, then
Therefore, for any two distinct edges and in such that their four endpoints are not collinear, the line segments and do not intersect.
We show that the non-crossing property enables us to compute an eligible edge decomposition , which is a set of non-crossing line segments, such that for every edge of , it is contained in a segment of . Note that induces a plane graph whose vertices come from .
Since the definition of eligible edges in our setting is identical to that in Sharathkumar [20], we can adopt their algorithm for computing the eligible edge decomposition. However, a minor technical hurdle arises in the initialization phase. It uses an approximate perfect matching obtained from the first phase, but in our setting, an approximate matching we have is not necessarily perfect if we look at the upper layer only. More specifically, it first computes all point-line pairs with such that contains an eligible edge incident to . The number of such pairs is . For a point , one can compute all eligible edges incident to it in time per edge using a dynamic weighted nearest neighbor data structure. However, it is possible that a single line contains many different eligible edges incident to . Then a single line can be discovered multiple times, which leads to quadratic running time in the worst case. To avoid this, as initialization, it computes just one line for each point in containing an eligible edge incident to in time in total using . Later, it considers each point in one by one and computes all pairs such that is not found in the initialization. Even in this case, a single line can be discovered multiple times, but the total number of pairs found in this way is , which leads to near-linear running time. The perfect matching can be used in the initialization; since an edge of is eligible, its extension contains an eligible edge incident to (and ). But we can perform this initialization using a dynamic weighted nearest-neighbor data structure, and this does not increase the overall running time. The full details of this modified construction are deferred to the full version of this paper.
Construction of the candidate subgraph.
We now construct the candidate edge set of size using the eligible edge decomposition . As mentioned earlier, if no four points of are collinear, we can simply construct by adding all eligible edges (the edges of ), their mirrored edges in the lower layer, and all link edges between the layers. However, in the general case, the number of eligible edges can be , making it impossible to include all of them.
Instead, we select a restricted subset of eligible edges as follows. For each pair , let be the set of points in lying on the open segment between and . For a minimum-cost perfect matching of , any edge incident to a vertex must have its other endpoint in . Consequently, for the endpoints and , there are four possible configurations based on whether and are matched with points in . For each configuration, we can identify the specific edges of incident to points in in time without computing the entire matching. More specifically, let be the set of points matched with elements in under . By solving the local matching problem for , we extract the necessary edges to be included in , ensuring the total size remains . For the local matching problem, since the vertices of are collinear, the problem is restricted to one dimension. This problem reduces to the minimum-cost matching problem on , where leaving a vertex unmatched incurs a penalty of , where for a vertex and for a vertex . Therefore, the local matching problem can be solved in time by Theorem 2. We do this for all the four configurations, and then take the union of the resulting edges. Then is defined as the union of all such edges in , their mirrored edges in the lower layer, and all the link edges. Then the size of is , and it can be computed in time.
We show that contains a minimum-cost perfect matching of . For this, we use the following technical lemma justifying that focusing on the upper layer during the construction of is sufficient. We say a matching is symmetric if an edge in the upper layer is contained in if and only if its mirrored edge is contained in .
Lemma 12.
Let be a subgraph of induced by edges in the upper layer, their mirrored edges in the lower layer, and all link edges. There exists a minimum-cost perfect matching of that is symmetric.
Proof.
Let be an arbitrary minimum-cost perfect matching of . Let be the number of edges in that belong to the upper layer. Each such edge covers one vertex in and one in . Because is a perfect matching, any vertex in the upper layer not matched with a vertex in the upper layer must be matched to its corresponding copy in the lower layer via a link edge. This implies that exactly vertices in the lower layer are not covered by link edges. To satisfy the perfect matching requirement, these vertices must be matched to each other using edges in the lower layer.
Now, consider the cost of these edges. By construction, the cost of any edge in the lower layer is zero. Therefore, we can replace the existing lower-layer edges in with the “mirrored” edges of the upper-layer matching without changing the total cost of the matching. This substitution results in a new perfect matching that remains optimal and satisfies the symmetry condition: is in if and only if is in . Therefore, the lemma holds.
Lemma 13.
There exists a minimum-cost perfect matching of such that .
Proof.
Let be a minimum-cost perfect matching of such that (i) all edges of belonging to the upper layer are contained in , and (ii) is symmetric, which always exists by Lemma 10 and by Lemma 12.
To show that , we consider the eligible edge decomposition . Every edge in the upper layer must be contained within some segment . For each such segment, let be the set of points of lying in the open interval between and . By the construction of , any edge in incident to a vertex in must have its other endpoint in . This local constraint implies that the matching within each segment can be optimized independently based on the four possible configurations of the endpoints and . Since is constructed by taking the union of the optimal local matchings for all four configurations across all segments in , it follows that the edges of are included in . Thus, the subgraph of induced by contains a minimum-cost perfect matching of .
Therefore, the candidate edge set can be computed in time in total, and the problem reduces to computing a minimum-cost perfect matching on the subgraph of induced by . For an illustration of , see Figure 2.
It is worth noting the structural distinction between our construction and the one-to-one setting addressed by Sharathkumar [20]. In the one-to-one case, for each segment , it is sufficient to consider at most two configurations of the endpoints and , which makes the resulting graph planar. This is because the difference between the numbers of points in and of points in restricts the possible configurations of and . In the many-to-many setting, however, this difference does not inherently reduce the number of configurations. Consequently, we must consider the union of local optimal matchings for all four configurations, which renders the resulting candidate graph non-planar.
4.2 Divide-and-Conquer Algorithm via Planar Separators
In this section, we present a divide-and-conquer algorithm to compute a minimum-cost perfect matching of the candidate graph . Our algorithm recursively partitions into disjoint vertex sets by removing a subset of vertices. We first compute the optimal matching for the subgraph induced by the disjoint sets. Subsequently, in the conquer phase, we reintroduce the removed vertices and gradually update the matching to obtain a minimum-cost perfect matching of using augmenting paths.
We begin by recalling the planar separator theorem, which serves as the foundation for our graph partitioning strategy. Lipton and Tarjan [16] established the following result for planar graphs.
Theorem 14 ([16]).
Let be a planar graph with vertices. The vertices of can be partitioned in time into three disjoint sets such that (i) no edge connects a vertex in with a vertex in , (ii) , and (iii) .
We call a balanced separator of . While is not necessarily planar, its inherent planar structure is derived from the eligible edge decomposition . Let be the set of endpoints of the edges (segments) in , and let be the planar skeleton defined by , that is, it is the planar graph induced by the edges of .
We apply the planar separator theorem to to induce a separation of . Let be a partition of obtained by applying Theorem 14 to , where is a balanced separator of . Let and denote the mirrored sets of and , respectively, in the lower layer. We make the following observation regarding the sizes of these sets.
Observation 15.
Let be the mirrored set of in the lower layer. Then, , and .
Using the partition of , we partition the vertex set of into and with and as follows. For this, it suffices to partition the vertices of contained in the open segments of . We call such vertices interior vertices. For each interior vertex of , we assign it to the set based on the endpoints of the segment of containing . Specifically, if the segment of containing has an endpoint in (in ), we put and to (to ). Otherwise, both endpoints of the segment are contained in . In this case, we put and to . Here, notice that no segment of has endpoints both in and since separates and .
Lemma 16.
No edge in connects a vertex in to a vertex in .
Proof.
We prove this by examining the three types of edges in . In the first case that belongs to the upper layer, every eligible edge in the upper layer is contained in a segment in . If an endpoint of is contained in (or in ), both endpoints of are in (or ), or one belongs to (or ) and the other to . If both endpoints of are contained in , both endpoints of are contained in . Thus in any case, the lemma holds.
In the other cases, the lemma holds due to the symmetric construction of following Lemma 12. Specifically, a vertex and its copy belong to the same set among and . Therefore, in the case that belongs to the lower layer, or is a link edge, the lemma holds immediately. We refer to as the prism separator of . We classify each vertex of the prism separator into two types. We call a vertex of a skeleton vertex of and a vertex of an interior vertex of . See Figure 2.
Divide-and-Conquer Algorithm.
We now present a detailed divide-and-conquer algorithm for computing a minimum-cost perfect matching of . The algorithm first computes the partition of the vertex set in linear time and recursively finds minimum-cost perfect matchings for the subgraphs induced by and . Note that the subgraph induced by (and ) has a perfect matching due to its prism structure. Since no edges connect and , the union of their optimal matchings is a minimum-cost perfect matching for the subgraph induced by . To obtain the optimal matching for the entire graph, one might consider extending this matching by adding all vertices of the separator one by one using the following lemma. Here, a minimum-cost maximum-cardinality matching is defined as the matching with the minimum total cost among all matchings of maximum possible cardinality.
Lemma 17 ([17]).
Let be a graph with vertices and edges associated with edge costs, and let be a vertex of . Given a minimum-cost maximum-cardinality matching of , a minimum-cost maximum-cardinality matching of can be computed in time.
However, a naive application of Lemma 17 to all vertices in would take time, which is inefficient since can be as large as . To address this, we observe that consists of skeleton vertices and a potentially large number of interior vertices. Our strategy is to handle the skeleton vertices using Lemma 17, while the interior vertices are handled efficiently by exploiting their 1D nature and pre-computed optimal matchings.
The algorithm processes the subgraph of in each recursive step as follows. Using the subgraph of induced by , we compute a balanced separator and a partition of . As mentioned earlier, we compute a minimum-cost perfect matching of in linear time. Now consider the internal vertices of . We decompose them into subsets such that each subset consists of the internal vertices lying on the same segment of . For each subset , we retrieve its optimal matching of using the pre-computed 1D matching from Section 4.1, where is the copy of in the lower layer. An optimal matching of can be obtained from a minimum-cost matching of with penalties, which can be found in near-linear time. Since no edge of connects two vertices from different subsets, the union of the all these matchings is a minimum-cost maximum-cardinality matching of . Finally, we reintroduce the skeleton vertices of into the matching using Lemma 17, where . We iteratively apply Lemma 17 for each skeleton vertex of to update . In this way, each recursion step takes time in total.
In the base case that the number of (skeleton) vertices of is , we compute a minimum-cost maximum-cardinality matching of the (non-skeleton) vertices of using their 1D nature in time. Then we reintroduce the skeleton vertices with Lemma 17. This takes time in total.
Complexity Analysis.
To bound the overall time complexity, let be the number of vertices of . At depth of the recursion, let denote the disjoint subgraphs, where each contains edges and skeleton vertices along with their copies. By Theorem 14 and Observation 15, the number of skeleton vertices shrinks by a factor of at least per level, yielding . Furthermore, since the subgraphs at any depth are edge-disjoint, .
In the conquer phase, merging the sub-solutions for requires augmentations. Since each augmentation takes time by Lemma 17, the total time for depth is:
Because , the time for each level decreases geometrically. The total running time of the divide-and-conquer algorithm is thus dominated by the root level, which is .
Overall complexity and proof of Theorem 1.
We compute an approximate matching and its dual weights for the scaled graph with a suitable scaling factor in time. The candidate graph can be computed in time, and the divide-and-conquer algorithm takes time. Therefore, the total time complexity of our algorithm remains .
5 Conclusion
In this paper, we presented an exact -time algorithm for the many-to-many matching problem on planar point sets with integer coordinates. Our approach relies on a reduction to perfect matching on a prism graph, a scaling framework, and a planar separator-based divide-and-conquer strategy.
Extending this framework to non-integer coordinates or higher dimensions () poses fundamental challenges. In particular, our framework relies on Lemma 11. In continuous domains, the additive error in the inequality in Lemma 11 is no longer bounded, and thus it seems hard to apply our framework to continuous domains. For higher dimensions, geometric graphs lack planarity, preventing the use of a balanced vertex separator of size. Moreover, in higher dimensions, maintaining the dynamic weighted nearest-neighbor data structures required in the scaling step becomes substantially more difficult. We leave the problem of designing a subquadratic-time algorithm for many-to-many matching on higher dimensions or continuous domains as an open problem.
References
- [1] Helmut Alt, Kurt Mehlhorn, Hubert Wagener, and Emo Welzl. Congruence, similarity, and symmetries of geometric objects. Discrete & Computational Geometry, 3(3):237–256, 1988. doi:10.1007/BF02187910.
- [2] Shinwoo An, Eunjin Oh, and Jie Xue. Approximation algorithms for the geometric multimatching problem. In Proceedings of the 57th Annual ACM Symposium on Theory of Computing (STOC 2025), pages 2317–2328, 2025. doi:10.1145/3717823.3718147.
- [3] Sayan Bandyapadhyay, Anil Maheshwari, and Michiel Smid. Exact and approximation algorithms for many-to-many point matching in the plane. In Proceedings on the 32nd International Symposium on Algorithms and Computation (ISAAC 2021), volume 212 of LIPIcs, pages 44:1–44:14, 2021. doi:10.4230/LIPIcs.ISAAC.2021.44.
- [4] Sayan Bandyapadhyay and Jie Xue. An -time approximation scheme for geometric many-to-many matching. In Proceedings of the 40th International Symposium on Computational Geometry (SoCG 2024), pages 12:1–12:15, 2024. doi:10.4230/LIPIcs.SOCG.2024.12.
- [5] Justin Colannino, Mirela Damian, Ferran Hurtado, Stefan Langerman, Henk Meijer, Suneeta Ramaswami, Diane L. Souvaine, and Godfried Toussaint. Efficient many-to-many point matching in one dimension. Graphs and Combinatorics, 23:169–178, 2007. doi:10.1007/S00373-007-0714-3.
- [6] Justin Colannino and Godfried Toussaint. A faster algorithm for computing the link distance between two point sets on the real line. Technical report, Technical Report SOCS-TR-2005.5, McGill University, School of Computer Science, 2005.
- [7] Thomas Eiter and Heikki Mannila. Distance measures for point sets and their computation. Acta Informatica, 34(2):109–133, 1997. doi:10.1007/S002360050075.
- [8] Michael L. Fredman and Robert Endre Tarjan. Fibonacci heaps and their uses in improved network optimization algorithms. Journal of the ACM, 34(3):596–615, 1987. doi:10.1145/28869.28874.
- [9] Harold N. Gabow. A data structure for nearest common ancestors with linking. ACM Trans. Algorithms, 13(4):45:1–45:28, 2017. doi:10.1145/3108240.
- [10] Harold N. Gabow and Robert Endre Tarjan. Faster scaling algorithms for network problems. SIAM Journal on Computing, 18(5):1013–1036, 1989. doi:10.1137/0218069.
- [11] Akshaykumar Gattani, Sharath Raghvendra, and Pouyan Shirzadian. A robust exact algorithm for the Euclidean bipartite matching problem. Proceedings of the 37th Annual Conference on Neural Information Processing Systems (NeurIPS 2023), 36:51706–51718, 2023.
- [12] Haim Kaplan, Wolfgang Mulzer, Liam Roditty, Paul Seiferth, and Micha Sharir. Dynamic planar voronoi diagrams for general distance functions and their algorithmic applications. Discrete & Computational Geometry, 64(3):838–904, 2020. doi:10.1007/S00454-020-00243-7.
- [13] Judith Keijsper and Rudi Pendavingh. An efficient algorithm for minimum-weight bibranching. Journal of Combinatorics Theory, Series B, 73(2):130–145, 1998. doi:10.1006/JCTB.1998.1817.
- [14] David G. Kirkpatrick. Optimal search in planar subdivisions. SIAM Journal on Computing, 12(1):28–35, 1983. doi:10.1137/0212002.
- [15] Harold W Kuhn. The hungarian method for the assignment problem. Naval research logistics quarterly, 2(1-2):83–97, 1955.
- [16] Richard J Lipton and Robert Endre Tarjan. A separator theorem for planar graphs. SIAM Journal on Applied Mathematics, 36(2):177–189, 1979.
- [17] Richard J. Lipton and Robert Endre Tarjan. Applications of a planar separator theorem. SIAM Journal on Computing, 9(3):615–627, 1980. doi:10.1137/0209046.
- [18] Qin Lv, Moses Charikar, and Kai Li. Image similarity search with compact data structures. In Proceedings of the 13th ACM International Conference on Information and Knowledge Management (CIKM 2004), pages 208–217, 2004. doi:10.1145/1031171.1031213.
- [19] David Mumford. Mathematical theories of shape: Do they model perception? In Geometric methods in computer vision, volume 1570, pages 2–10, 1991.
- [20] R. Sharathkumar. A sub-quadratic algorithm for bipartite matching of planar points with bounded integer coordinates. In Proceedings of the 29th Annual Symposium on Computational Geometry (SoCG 2013), pages 9–16, 2013. doi:10.1145/2462356.2480283.
- [21] R. Sharathkumar and Pankaj K. Agarwal. Algorithms for the transportation problem in geometric settings. In Proceedings of the 23rd Annual ACM-SIAM Symposium on Discrete Algorithms (SODA 2012), pages 306–317, 2012. doi:10.1137/1.9781611973099.29.
- [22] Ranjith Unnikrishnan and Martial Hebert. Measures of similarity. In Proceedings of the 7th IEEE Workshops on Applications of Computer Vision (WACV/MOTION 2005), volume 1, pages 394–394. IEEE, 2005.
- [23] Remco C. Veltkamp and Michiel Hagedoorn. State of the art in shape matching. Principles of visual information retrieval, pages 87–119, 2001. doi:10.1007/978-1-4471-3702-3_4.
