# 最大基数匹配

**最大基数匹配**（maximum cardinality matching）是图中规模尽可能大的匹配：一组两两不共享端点的边，其选取使边数尽可能多。这样的匹配并不总是唯一的；寻找它是组合优化的经典问题，在二分图和一般图上都可在多项式时间内求解。<sup>[1](https://networkx.org/documentation/networkx-2.6.2/reference/algorithms/generated/networkx.algorithms.bipartite.matching.hopcroft_karp_matching.html)</sup>

| 关键事实 | 细节 |
|---|---|
| 定义 | 匹配是一组不共享任何节点的边；最大基数匹配是边数尽可能多的匹配，且它并不总是唯一的<sup>[1](https://networkx.org/documentation/networkx-2.6.2/reference/algorithms/generated/networkx.algorithms.bipartite.matching.hopcroft_karp_matching.html)</sup> |
| 最优性判定 | 匹配 M 是最大基数匹配，当且仅当不存在关于 M 的增广路径<sup>[2](https://web.cs.dal.ca/~nzeh/Teaching/4113/book/matching/bipartite_maximum_matching/augmenting_paths.html)</sup> |
| 二分图情形 | 霍普克罗夫特–卡普（Hopcroft–Karp）算法（1973）在 n 个顶点、m 条边的二分图中，以正比于 (m + n)√n 的时间求出最大匹配，至多经过 2√n 个阶段<sup>[3](https://web.eecs.umich.edu/~pettie/matching/Hopcroft-Karp-bipartite-matching.pdf)</sup><sup> • </sup><sup>[4](https://www.cs.tau.ac.il/~zwick/grad-algo-13/match.pdf)</sup> |
| 一般图 | 埃德蒙兹（Edmonds）的花算法（见 1965 年《路径、树与花》（*Paths, Trees, and Flowers*））是第一个跳出“全幺模”模式的、求解图问题的好算法，其复杂度被他保守地定为 O(n<sup>4</sup>)<sup>[5](https://nvlpubs.nist.gov/nistpubs/sp958-lide/html/140-144.html)</sup><sup> • </sup><sup>[19](https://nvlpubs.nist.gov/nistpubs/sp958-lide/140-144.pdf)</sup> |
| 最快的一般图算法 | 米卡利–瓦齐拉尼（Micali–Vazirani）算法（1980）运行时间为 O(√\|V\|·\|E\|)，至今仍是该问题已知最高效的算法；其第一个完整的正确性证明于 2020 年才出现<sup>[6](https://arxiv.org/abs/2012.03582)</sup><sup> • </sup><sup>[7](https://www.researchgate.net/publication/221499631_An_Osqrtv_E_Algorithm_for_Finding_Maximum_Matching_in_General_Graphs)</sup> |
| 二分图的最新纪录 | 陈等人（Chen et al.，2022）实现了二分图匹配的 m<sup>1+o(1)</sup> 时间；丘兹霍伊与坎纳（Chuzhoy and Khanna，2024）给出了纯组合的 Õ(m<sup>1/3</sup>n<sup>5/3</sup>) 算法<sup>[8](https://arxiv.org/abs/2312.12584)</sup> |

## 匹配与增广路径

每个匹配算法的核心工具都是增广路径。关于匹配 M 的增广路径是一条交替路径——它的边在 M 中的边与不在 M 中的边之间交替——且它的两个端点都不被 M 匹配。把这样一条路径上每条边的状态翻转，就得到恰好多一条边的新匹配：对增广路径 P，对称差 M′ = M ⊕ P 是一个基数为 |M′| = |M| + 1 的匹配。<sup>[2](https://web.cs.dal.ca/~nzeh/Teaching/4113/book/matching/bipartite_maximum_matching/augmenting_paths.html)</sup>

由此得到最优性的完整刻画：匹配 M 是最大基数匹配，当且仅当图中不存在关于 M 的增广路径。若 M 不是最大的，取一个更大的匹配 M′，对 M ⊕ M′ 作分解即可看出，其中必有一条路径是关于 M 的增广路径。<sup>[2](https://web.cs.dal.ca/~nzeh/Teaching/4113/book/matching/bipartite_maximum_matching/augmenting_paths.html)</sup> 由此得到的通用算法从空匹配开始，反复寻找增广路径并沿之增广，直到不存在这样的路径为止。<sup>[4](https://www.cs.tau.ac.il/~zwick/grad-algo-13/match.pdf)</sup>

## 二分图情形

在二分图中，顶点分成两个集合，每条边都连接分别来自两个集合的一个顶点，于是问题化为最大流问题：求一个最佳匹配，等价于在一个每条边容量均为 1 的有向图中求最大 s-t 流；对该网络施用基本的福特–富尔克森（Ford–Fulkerson）方法，即得到 O(mn) 时间的算法。<sup>[8](https://arxiv.org/abs/2312.12584)</sup>

**霍普克罗夫特–卡普。** 1973 年，约翰·E·霍普克罗夫特（John E. Hopcroft）与理查德·M·卡普（Richard M. Karp）说明了如何加速这一简单方案。他们的算法不是一次只找一条增广路径，而是用广度优先搜索和深度优先搜索，在每个阶段找出一个极大的、由尽可能短的内部不相交增广路径构成的集合，把运行时间改进到 O(m√n)。<sup>[8](https://arxiv.org/abs/2312.12584)</sup> 分析表明，相继各阶段所找到的最短增广路径严格变长，因此在 √n 个阶段之后，匹配与最大匹配至多相差 √n 条边，而至多 2√n 个阶段后即得到最大匹配。<sup>[4](https://www.cs.tau.ac.il/~zwick/grad-algo-13/match.pdf)</sup>

二分图最大匹配还通过柯尼希（Kőnig）定理与顶点覆盖相联系：在二分图中，最大匹配的大小等于最小顶点覆盖的大小，而匹配算法所构造的交替森林可在 O(m) 的额外时间内构造出这样一个覆盖。相反，对一般图而言，最小顶点覆盖是 NP 完全的。<sup>[4](https://www.cs.tau.ac.il/~zwick/grad-algo-13/match.pdf)</sup>

## 一般图与花

在非二分图中，一次搜索一条增广路径的朴素策略仍然可行，但很慢：找一条增广路径需要 O(nm) 时间，而任何匹配至多能被增广 n/2 次，于是得到一个 O(n<sup>2</sup>m) 时间的算法。<sup>[9](https://web.cs.dal.ca/~nzeh/Teaching/4113/book/matching/general_maximum_cardinality_matching/intro.html)</sup>

**花算法。** 杰克·埃德蒙兹（Jack Edmonds）于 1961 年在加利福尼亚州圣莫尼卡（Santa Monica）的兰德公司（RAND Corporation）举办的夏季研讨会上，找到了最大匹配问题的一个高效算法；他在 1965 年的论文《路径、树与花》中把它完整写出，并保守地把复杂度估计为 O(n<sup>4</sup>)。该算法从所有未匹配顶点出发，同时运行交替的广度优先搜索；当它遇到某一类特殊的奇圈——由交替森林中的一条路径加上一条不在森林中的边构成，称为花——就把这朵花收缩成单个顶点，并在更小的图上递归。收缩图中的增广路径可以提升回原图中的增广路径。<sup>[5](https://nvlpubs.nist.gov/nistpubs/sp958-lide/html/140-144.html)</sup><sup> • </sup><sup>[9](https://web.cs.dal.ca/~nzeh/Teaching/4113/book/matching/general_maximum_cardinality_matching/intro.html)</sup>

这一突破既是计算上的，也是概念上的。当时已知的所有好的图论算法处理的都是“全幺模”问题，如最短路和网络流，它们可以表述为保持整性的线性规划；埃德蒙兹的匹配算法是第一个跳出这一模式的好算法。该论文还贡献了柯尼希定理的一个推广，它适用于各种图中的匹配，而不只是二分图。<sup>[5](https://nvlpubs.nist.gov/nistpubs/sp958-lide/html/140-144.html)</sup> 为表彰这项工作及相关贡献，埃德蒙兹于 1985 年获得 INFORMS 颁发的约翰·冯·诺依曼理论奖。<sup>[10](https://www.nist.gov/mathematics-statistics/first-mathematical-theory-efficient-combinatorial-algorithms-jack-edmonds)</sup>

**米卡利–瓦齐拉尼。** 正如二分图匹配从 O(nm) 改进到 O(m√n)，埃德蒙兹的算法也已被降到 O(nm)，并通过将其思想与霍普克罗夫特–卡普的阶段框架相结合而降到 O(m√n)。<sup>[9](https://web.cs.dal.ca/~nzeh/Teaching/4113/book/matching/general_maximum_cardinality_matching/intro.html)</sup> 1980 年的米卡利–瓦齐拉尼算法以分阶段的方式达到 O(√|V|·|E|) 时间：每个阶段找出一个极大的、由不相交的最短增广路径构成的集合，并以特殊方式处理花，使一个阶段可以用 O(|E|) 时间实现。<sup>[7](https://www.researchgate.net/publication/221499631_An_Osqrtv_E_Algorithm_for_Finding_Maximum_Matching_in_General_Graphs)</sup> 这一界自 1980 年以来一直未被打破，该算法至今仍是一般图最大基数匹配已知最高效的算法；其第一个完整而正确的正确性证明由维贾伊·V·瓦齐拉尼（Vijay V. Vazirani）于 2020 年给出。<sup>[6](https://arxiv.org/abs/2012.03582)</sup>

## 算法纪录

运行时间呈现出清晰的演进。对二分图而言，霍普克罗夫特–卡普的 O(m√n) 统治了数十年，只有在非常稠密的图上例外——那里快速矩阵乘法给出 O(n<sup>2.371</sup>)。2013 年马德里（Madry）引入了基于内点法的连续技术，在稀疏图上取得快得多的运行时间，这一路线最终在 2022 年由陈等人取得突破，实现了在 m<sup>1+o(1)</sup> 时间内求解二分图最大匹配。丘兹霍伊与坎纳回答了“连续技术是否不可或缺”这一问题，给出了纯组合的、Õ(m<sup>1/3</sup>n<sup>5/3</sup>) 时间的确定性算法，它在 m = ω(n<sup>7/4</sup>) 的图上优于霍普克罗夫特–卡普，在稠密图上还胜过矩阵乘法途径；2024 年的一项后续工作给出了随机化的 n<sup>2+o(1)</sup> 时间组合算法。<sup>[8](https://arxiv.org/abs/2312.12584)</sup><sup> • </sup><sup>[11](https://arxiv.org/abs/2405.20861)</sup>

最坏情况界并不是全部。一项平均情况分析表明，霍普克罗夫特–卡普与米卡利–瓦齐拉尼这类增广路径算法虽然最坏情况运行时间为 O(m√n)，但在随机图上以高概率只需 O(m log n) 时间。<sup>[12](https://www.cs.au.dk/~gerth/alcom-ft/TR/ALCOMFT-TR-03-111.html)</sup> 基于阶段的算法还能自适应于结构：它们在若干图类上以线性时间运行，在只需删除 k 个顶点即可归入这些图类的图上以 O(√k·m) 时间运行；不过阶段框架本身即使在路径、余图（cograph）和二分链图上仍需要 Ω(√n) 个阶段，因而需要 Ω(√n·m) 时间。<sup>[13](https://arxiv.org/abs/1904.11244)</sup> 在组合方法之外，1989 年发表的一种随机化代数算法作用于图的塔特（Tutte）矩阵；它比已知最好的组合算法慢，但概念简单、易于编程。<sup>[14](https://www.sciencedirect.com/science/article/pii/0196677489900059)</sup>

## 应用与计算

凡是需要尽可能完整地两两配对的地方，都会出现最大基数匹配。在肾脏交换计划中，人们为病人—捐献者对建立无向图，目标是找出相容交换的最大基数匹配。<sup>[15](https://www.cse.iitb.ac.in/~swaprava/courses/cs6002/scribed/lec03.pdf)</sup> 学生—项目分配问题同样建立在最大基数匹配之上，通常还叠加了偏好。<sup>[16](https://arxiv.org/abs/1403.0751)</sup> 在观察性统计中，基数匹配用于在具有指定基线特征的情况下，找出尽可能多的暴露者与未暴露者的配对。<sup>[17](https://arxiv.org/abs/2201.04276)</sup>

通用软件直接提供求解这一问题的接口。NetworkX 为二分图提供 `hopcroft_karp_matching`（也以 `maximum_matching` 为别名），返回的匹配是一个字典，未匹配的节点不作为键出现；它还提供 `max_weight_matching` 函数，其 `maxcardinality` 标志会在所有最大基数匹配中计算权重最大的最大基数匹配；其实现耗时 O(n<sup>3</sup>)。<sup>[1](https://networkx.org/documentation/networkx-2.6.2/reference/algorithms/generated/networkx.algorithms.bipartite.matching.hopcroft_karp_matching.html)</sup><sup> • </sup><sup>[18](https://networkx.org/documentation/stable/_modules/networkx/algorithms/matching.html)</sup>

## References

1. [hopcroft_karp_matching, NetworkX 2.6.2 documentation](https://networkx.org/documentation/networkx-2.6.2/reference/algorithms/generated/networkx.algorithms.bipartite.matching.hopcroft_karp_matching.html)
2. [Augmenting Paths, Algorithms II, Dalhousie University](https://web.cs.dal.ca/~nzeh/Teaching/4113/book/matching/bipartite_maximum_matching/augmenting_paths.html)
3. [Hopcroft, J. E. and Karp, R. M. (1973). An n^{5/2} Algorithm for Maximum Matchings in Bipartite Graphs, SIAM Journal on Computing](https://web.eecs.umich.edu/~pettie/matching/Hopcroft-Karp-bipartite-matching.pdf)
4. [Lecture notes on matching algorithms, U. Zwick, Tel Aviv University](https://www.cs.tau.ac.il/~zwick/grad-algo-13/match.pdf)
5. [Maximum Matching (Blossom) chapter, NIST](https://nvlpubs.nist.gov/nistpubs/sp958-lide/html/140-144.html)
6. [Vazirani, V. V. (2020). A Proof of the MV Matching Algorithm, arXiv](https://arxiv.org/abs/2012.03582)
7. [Micali, S. and Vazirani, V. V. (1980). An O(√|V|·|E|) Algorithm for Finding Maximum Matching in General Graphs, FOCS](https://www.researchgate.net/publication/221499631_An_Osqrtv_E_Algorithm_for_Finding_Maximum_Matching_in_General_Graphs)
8. [Chuzhoy, J. and Khanna, S. (2023). A Faster Combinatorial Algorithm for Maximum Bipartite Matching, arXiv](https://arxiv.org/abs/2312.12584)
9. [General Maximum-Cardinality Matching, Algorithms II, Dalhousie University](https://web.cs.dal.ca/~nzeh/Teaching/4113/book/matching/general_maximum_cardinality_matching/intro.html)
10. [First Mathematical Theory of Efficient Combinatorial Algorithms: Jack Edmonds, NIST](https://www.nist.gov/mathematics-statistics/first-mathematical-theory-efficient-combinatorial-algorithms-jack-edmonds)
11. [Chuzhoy, J. and Khanna, S. (2024). Maximum Bipartite Matching in n^{2+o(1)} Time via a Combinatorial Algorithm, arXiv](https://arxiv.org/abs/2405.20861)
12. [Improved average case analysis of the maximum cardinality matching problem, ALCOMFT-TR-03-111](https://www.cs.au.dk/~gerth/alcom-ft/TR/ALCOMFT-TR-03-111.html)
13. [Hegerfeld, F. and Kratsch, S. (2019). On adaptive algorithms for maximum matching, arXiv](https://arxiv.org/abs/1904.11244)
14. [Maximum matchings in general graphs through randomization, Journal of Algorithms (1989)](https://www.sciencedirect.com/science/article/pii/0196677489900059)
15. [Lecture notes on kidney exchange matching, IIT Bombay](https://www.cse.iitb.ac.in/~swaprava/courses/cs6002/scribed/lec03.pdf)
16. [Profile-based optimal matchings in the Student/Project Allocation problem, arXiv](https://arxiv.org/abs/1403.0751)
17. [Using Cardinality Matching to Design Balanced and Representative Samples for Observational Studies, arXiv](https://arxiv.org/abs/2201.04276)
18. [networkx.algorithms.matching source code, NetworkX 3.7 documentation](https://networkx.org/documentation/stable/_modules/networkx/algorithms/matching.html)
19. [nvlpubs.nist.gov](https://nvlpubs.nist.gov/nistpubs/sp958-lide/140-144.pdf)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 30, 2026; Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 物质世界与数学 › 数学与统计学 › 逻辑与离散数学 › General discrete mathematics and discrete structures › Graph theory › Computational graph problems and algorithms › Matching algorithms

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/maximum-cardinality-matching

English original: https://www.edgepedia.org/maximum-cardinality-matching
