Efficient Algorithms For Fully Dynamic Bipartite Matching In Metric Spaces

Pankaj K Agarwal, Oliver Chubet, Sharath Raghvendra, Arian ZamaniNeurIPS 2026

TL;DR

Comparing probability distributions via Optimal Transport (Wasserstein distance) boils down to pairing up sample points at minimum total distance—a problem that becomes painfully slow to recompute from scratch when data streams in and out. This paper introduces fast, "fully dynamic" data structures that maintain near-optimal point matchings on the fly as points are inserted or deleted. They beat long-standing accuracy bounds in high-dimensional geometric spaces and deliver the very first dynamic algorithm for general $p$-Wasserstein distances in arbitrary metric spaces.

What Problem Does This Paper Address?

Imagine you are monitoring a machine learning model in production for distributional drift, or dynamically allocating ride-share drivers to passengers. A principled way to compare two evolving datasets $A$ and $B$ (say, $n$ points each) is Optimal Transport (OT): pairing every point $a \in A$ with a unique point $b \in B$ to minimize the $p$-Wasserstein cost ($W_p$), defined as $\left(\sum \mathsf{d}(a,b)^p\right)^{1/p}$.

In streaming or live environments, points are constantly added and removed. Recomputing an optimal matching from scratch after every single update is computationally prohibitive. We need fully dynamic algorithms—data structures that support both insertions and deletions—that maintain an $\alpha$-approximate matching (within $\alpha$ times the optimal cost) rapidly.

Prior dynamic algorithms had major blind spots:

  1. The Curse of Dimensionality: In geometric spaces ($\mathbb{R}^d$), grid-based methods break down in high dimensions because local sub-problems blow up exponentially with $d$, while tree-embedding methods suffer in approximation quality or fail outside standard Euclidean ($\ell_2$) norms.
  2. Beyond $p=1$: Almost all existing dynamic work focuses on $W_1$ (Earth Mover's Distance). When $p \ge 2$—crucial for applications like Wasserstein gradient flows and generative modeling—raised distances $\mathsf{d}(x,y)^p$ violate the triangle inequality, breaking standard metric tricks. Prior to this paper, no fully dynamic algorithm with almost-linear update time existed for $W_p$ ($p \ge 2$) in general metric spaces.

Methods

The authors tackle both settings with two distinct algorithmic toolkits:

  • Geometric Spaces ($W_1$ in $\mathbb{R}^d$ under $\ell_q$-norms): Instead of rigid grids, the authors build a hierarchical tree partition using stable dynamic Low-Diameter Decompositions (LDDs)—randomized clusterings where nearby points rarely get split, and adding/removing a point doesn't reshuffle existing points. At each tree node, points are snapped to grids to create local matching sub-problems with bounded spread (the ratio of maximum to minimum pairwise distance, $\Delta$). Rather than recomputing local matchings from scratch on updates, they dynamically maintain them using Approximate Nearest-Neighbor (ANN) data structures and periodic reconstructions. To keep $\Delta$ from ruining the approximation factor, they maintain parallel data structures across multiple "guesses" of the optimal cost.
  • Arbitrary Metric Spaces ($W_p$ for integer $p \ge 1$): Extending a static $k$-level random sampling hierarchy (originally by Thorup and Zwick), the authors dynamically maintain a "proxy distance" $\mathsf{d}_{\mathcal{C}}$ that approximates the true metric. Deletions are handled lazily (points stay in the clustering skeleton until periodic rebuilds) so clusters don't violently shatter. Because insertions still alter proxy distances, standard primal-dual matching breaks. The authors invent a relaxed $(\tau, p)$-feasibility condition and run a single modified Hungarian (augmenting-path) search per update, accelerated by a weighted bichromatic closest-pair data structure.

Datasets

Not discussed in the paper. (This is a purely theoretical algorithms paper.)

Key Insights and Ideas

  • Don't recompute big clusters; maintain them dynamically: Previous geometric approaches failed in high dimensions because sub-clusters grew to $\Theta(n)$ points, making exact recomputation useless. Controlling the spread at each tree level rather than the size lets an ANN-powered dynamic solver update even massive clusters in sublinear time.
  • Bypassing the broken triangle inequality: By formulating a relaxed primal-dual feasibility condition—where dual weights are upper-bounded using $\tau^p \mathsf{d}(a,b)^p$ and lower-bounded on matched edges by $\mathsf{d}(a,b)^p$—the Hungarian search can operate directly on $p$-th power proxy costs without ever needing $\mathsf{d}(x,y)^p$ to obey the triangle inequality.
  • Stability is the secret sauce for dynamic hierarchies: Requiring LDDs to be stable ensures that inserting or deleting a point only ripples along a single root-to-leaf path of length $\widetilde{O}(1/\epsilon)$, keeping update cascades tightly contained.

Key Results

Let $n$ be the number of points per set and $\epsilon \in (0, 1]$ be a tunable accuracy/speed parameter ($\widetilde{O}$ hides polylogarithmic factors):

  • Breaking the Euclidean $O(\log n)$ barrier: For $W_1$ in high-dimensional Euclidean space ($\ell_2$) with bounded diameter, the algorithm achieves an expected $O(\epsilon^{-2}\sqrt{\gamma \log \gamma})$-approximation (where $\gamma = \min\{d, \log n\}$) in $\widetilde{O}(f(\epsilon)n^\epsilon + d^2)$ expected amortized update time. For fixed $\epsilon$, this improves the best-known dynamic approximation factor from $O(\log n)$ down to $O(\sqrt{\log n \log\log n})$.
  • General $\ell_q$-norms: In $\mathbb{R}^d$ under any $\ell_q$-norm ($q \ge 1$), they achieve either an $O(\epsilon^{-2}d^{|1/q - 1/2|}\sqrt{\gamma \log \gamma})$-approximation in $\widetilde{O}(f(\epsilon)n^\epsilon + d^2)$ time, or an $O(d\epsilon^{-3/2})$-approximation in $\widetilde{O}(n^\epsilon d^{(2/q)+\epsilon}\epsilon^{-2}\varphi(n, \epsilon^{-1/2}))$ time (where $\varphi$ is dynamic ANN query/update time).
  • First general dynamic $W_p$ solver: In any finite metric space and for any integer $p \ge 1$, their algorithm maintains an $O(1/\epsilon)$-approximate $W_p$-matching in $O(\epsilon^{-1}n^{1+\epsilon}\log n \log \Delta)$ expected amortized update time—upgrading prior work that only handled insertion-only $W_1$ with one side fixed.

Limitations and Future Work

  • Exponential $\epsilon$-dependence in Euclidean ANN: The fast Euclidean result relies on an underlying ANN data structure whose update/query time $f(\epsilon)$ scales exponentially in $1/\epsilon$.
  • Spread and Obliviousness Assumptions: The general metric $W_p$ update time depends logarithmically on the global spread $\Delta$ of all points ever seen, and relies on an oblivious update sequence (updates cannot adaptively target the algorithm's internal random coin flips).
  • Balanced Updates: Updates must arrive in pairs (inserting or deleting one point in $A$ and one in $B$ simultaneously) to keep $|A| = |B|$.
  • Open Questions: Finding sublinear-time dynamic $W_p$ ($p \ge 2$) algorithms specifically tailored for geometric spaces remains wide open.

Summary updated

Abstract

Given two point sets $A$ and $B$ of $n$ points each in a metric space $(\mathbb{X},\mathsf{d})$, a *matching* $M\subseteq A \times B$ is a set of $n$ pairs such that each point of $A\cup B$ appears exactly once in $M$. The $W_p$-cost of $M$ is $(\sum_{(a,b)\in M} \mathsf{d}(a,b)^p)^{1/p}$. $M$ is \textit{$\alpha$-approximate} if its cost is at most $\alpha$ times the minimum cost of a matching of $A$ and $B$. We study the problem of maintaining an $\alpha$-approximate matching of $A$ and $B$ under insertion and deletion of point pairs. For $A,B \subset \mathbb{R}^d$, with $\mathsf{d}(\cdot,\cdot)$ being the $\ell_q$-norm, $q \geq 1$, and for any parameter $\epsilon \in (0,1]$, we present the following two data structures for maintaining a matching under the $W_1$-cost: - The first one maintains an expected $O(d\epsilon^{-3/2})$-approximate matching in amortized update time $\widetilde{O}(n^\epsilon d^{(2/q)+\epsilon}\epsilon^{-2}\varphi(n,\epsilon^{-1/2}))$, where $\varphi(n,\alpha)$ denotes the update and query time of a dynamic $\alpha$-approximate nearest-neighbor data structure under the $\ell_q$-norm. - The second one maintains an expected $O(\epsilon^{-2}d^{|1/q-1/2|}\sqrt{\gamma\log\gamma})$-approximate matching in expected amortized update time $\widetilde O(n^\epsilon+d^2)$, where $\gamma=\min\{d,\log n\}$ and $\widetilde{O}$ hides polylogarithmic factors. For the Euclidean metric ($q=2$), the approximation factor becomes $O(\epsilon^{-2}\sqrt{\gamma\log\gamma})$. \end{itemize} For $A,B$ in an arbitrary finite metric space, any integer $p\geq1$, and any constant $\epsilon\in(0,1)$, we present a fully dynamic data structure that maintains an $O(1/\epsilon)$-approximate matching of $A$ and $B$ under the $W_p$-cost in amortized update time $O(\epsilon^{-1}n^{1+\epsilon}\log n\log\Delta)$, where $\Delta$ is the spread of $A\cup B$.
BibTeX
@inproceedings{agarwal2026efficient,
  author = {Pankaj K Agarwal and Oliver Chubet and Sharath Raghvendra and Arian Zamani},
  title = {{Efficient Algorithms For Fully Dynamic Bipartite Matching In Metric Spaces}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=1jMlnDilIo},
}
Figure