# 近似算法

近似算法是求解最优化问题的一种多项式时间算法，它对其解与最优解之间的距离提供了可证明的保证，即便在寻找精确最优解是 NP 难的情况下也是如此。该算法并不搜索绝对的最小值或最大值，而是保证在每一个输入上都给出“几乎”最优的解。<sup>[1](https://people.cs.umass.edu/~mcgregor/611S24/lec18.pdf)</sup>

| 关键事实 | 详情 |
|---|---|
| 保证 | 对于最小化问题，α-近似算法在每个实例上返回的解值至多为 α · OPT；对于最大化问题，至少为 OPT/α。精确的多项式算法即是 1-近似算法。<sup>[2](https://users.ece.utexas.edu/~garg/publicCompanion/chapter14-classical.html)</sup> |
| 顶点覆盖 | 反复选取一条未被覆盖的边并将其两个端点加入覆盖集，可在 O(\|V\| + \|E\|) 时间内得到 2-近似。<sup>[2](https://users.ece.utexas.edu/~garg/publicCompanion/chapter14-classical.html)</sup> |
| 集合覆盖 | 贪心算法（每次选取覆盖最多未覆盖元素的集合）达到 H<sub>n</sub>-近似，其中 H<sub>n</sub> = 1 + 1/2 + ⋯ + 1/n ≈ ln n。<sup>[2](https://users.ece.utexas.edu/~garg/publicCompanion/chapter14-classical.html)</sup> |
| 集合覆盖的紧致性 | 费格（1998）证明除非 P = NP，否则不存在多项式算法达到 (1 − ε) ln n，因此贪心算法的比值本质上是最优的。<sup>[2](https://users.ece.utexas.edu/~garg/publicCompanion/chapter14-classical.html)</sup> |
| 顶点覆盖的困难性 | 迪努尔与萨夫拉（2005）证明了最小顶点覆盖在因子 1.3606 以内是 NP 难近似的。<sup>[3](https://annals.math.princeton.edu/2005/162-1/p08)</sup> |
| 近似方案 | PTAS 对固定的 ε 在多项式时间内达到 (1 + ε) · OPT；FPTAS 还要求时间关于 1/ε 是多项式的，并且在假设 P ≠ NP 的前提下，这是 NP 难问题上所能期望的最好结果。<sup>[4](https://people.csail.mit.edu/ghaffari/AA19/AAscript.pdf)</sup> |
| 背包问题 | 对物品利润取整并运行精确动态规划，可得到返回价值至少为 (1 − ε) · OPT 的 FPTAS。<sup>[4](https://people.csail.mit.edu/ghaffari/AA19/AAscript.pdf)</sup> |

## 近似比

近似算法的质量由其性能比衡量，即算法解值与最优值之比在所有输入上的最坏情况。对于最小化问题，该比值为 max C<sub>alg</sub>(x)/C<sub>opt</sub>(x)；对于最大化问题，为 max C<sub>opt</sub>(x)/C<sub>alg</sub>(x)。<sup>[1](https://people.cs.umass.edu/~mcgregor/611S24/lec18.pdf)</sup> 因此，c-近似算法在该问题的所有实例上的代价至多为最优代价的 c 倍。<sup>[5](https://github.com/brenns10/notes/blob/master/eecs477.org)</sup>

可达比值的图景因问题而异，差异极大。有些 NP 难问题允许常数因子近似，有些只允许 O(log n) 的比值，还有些在假设 P ≠ NP 的前提下完全不允许常数因子近似。<sup>[2](https://users.ece.utexas.edu/~garg/publicCompanion/chapter14-classical.html)</sup> 证明比值界通常意味着将计算所得解的值与最优解的下界（对最小化问题）或上界（对最大化问题）进行比较，因为 OPT 本身是未知的。<sup>[6](https://web.cs.dal.ca/~nzeh/Teaching/4113/book/greedy_approx/greedy_set_cover/approximaiton_ratio.html)</sup>

## 顶点覆盖：一个 2-近似

最小顶点覆盖要求找出触及图中每条边的最小顶点集。经典算法反复选取任意一条未被覆盖的边，将其两个端点加入覆盖集，并删除所有关联边。<sup>[2](https://users.ece.utexas.edu/~garg/publicCompanion/chapter14-classical.html)</sup>

分析基于算法所选取的边集 F。这些边构成一个匹配，所生成的覆盖集大小为 |C| = 2|F|，而任何顶点覆盖都必须包含 F 中每条边的至少一个端点，因此 OPT ≥ |F|。所以 |C| ≤ 2 · OPT。<sup>[2](https://users.ece.utexas.edu/~garg/publicCompanion/chapter14-classical.html)</sup> 配合适当的边数据结构，该算法运行时间为 O(|V| + |E|)。<sup>[2](https://users.ece.utexas.edu/~garg/publicCompanion/chapter14-classical.html)</sup> 同样的思想可推广到超图，其中超边的极大匹配可给出最小顶点覆盖的 f-近似，f 为最大超边的大小。<sup>[4](https://people.csail.mit.edu/ghaffari/AA19/AAscript.pdf)</sup>

因子 2 已接近已知最好结果。上述分析是紧的，而顶点覆盖已知最好的算法比值为 2 − Θ(1/√log |V|)，由卡拉科斯塔斯（2004）给出。<sup>[7](https://webdocs.cs.ualberta.ca/~mreza/courses/Approx11/lecture1.pdf)</sup><sup> • </sup><sup>[14](https://eccc.weizmann.ac.il/eccc-reports/2004/TR04-084/index.html)</sup> 在困难性方面，分别来自[耶路撒冷希伯来大学](https://www.edgepedia.org/zh/hebrew-university-of-jerusalem)和特拉维夫大学的迪努尔与萨夫拉 在《[数学年刊](https://www.edgepedia.org/zh/annals-of-mathematics)》上证明了该问题在因子 1.3606 以内是 NP 难近似的，推广了此前的 PCP 与近似困难性技术。<sup>[3](https://annals.math.princeton.edu/2005/162-1/p08)</sup>

## 集合覆盖：贪心的对数保证

最小集合覆盖取一个含 n 个元素的全集 U 和一个子集族，要求用最少的子集使其并集为 U。贪心算法反复选取覆盖当前未覆盖元素最多的集合，移除这些元素，然后重复。<sup>[2](https://users.ece.utexas.edu/~garg/publicCompanion/chapter14-classical.html)</sup>

该保证来自一个计数论证。若存在大小为 k 的覆盖，则在每一步，k 个最优集合合起来覆盖所有剩余元素，因此其中至少一个覆盖了至少 1/k 比例的未覆盖元素。于是 t 个集合之后未覆盖元素的数量至多为 n(1 − 1/k)<sup>t</sup> < n·e<sup>−t/k</sup>，这里用到了 x > 0 时 1 − x < e<sup>−x</sup> 的不等式；当 t = k ln n 时该值降到 1 以下，因此所有元素都被覆盖，贪心解的大小至多为 k ln n。<sup>[8](https://courses.cs.washington.edu/courses/cse421/24au/lectures/lecture25-approximation-A.pdf)</sup>

一个精细的记账论证可以改进常数。当覆盖某元素的集合 S 被加入时，该元素被记上价格 p<sub>e</sub> = w<sub>S</sub>/|S \ C|，于是总覆盖权重等于价格之和；按元素被覆盖的时刻排序，可证明每个价格满足 p<sub>e<sub>i</sub></sub> ≤ OPT/(n − i + 1)，从而 w(C) ≤ OPT · H<sub>n</sub>，其中 H<sub>n</sub> = Σ<sub>i=1</sub><sup>n</sup> 1/i 是第 n 个调和数。由于 ln(n + 1) ≤ H<sub>n</sub> ≤ ln n + 1，比值为 Θ(lg n)。<sup>[6](https://web.cs.dal.ca/~nzeh/Teaching/4113/book/greedy_approx/greedy_set_cover/approximaiton_ratio.html)</sup> 赫瓦塔尔 1979 年的分析对带权问题给出了 (ln B + 1) 的比值，其中 B 是最大子集的大小。<sup>[9](https://i.cs.hku.hk/~hkual/Notes/Greedy/Set%20cover%20problem.html)</sup> 斯拉维克（1997）将贪心界改进为 ln n − ln ln n + Θ(1)。<sup>[10](https://arxiv.org/abs/1612.01610)</sup>

这个对数比值本质上已是最好的可能结果。费格于 1998 年证明，除非 P = NP，否则不存在多项式时间算法能达到集合覆盖的 (1 − ε) ln n 近似，这也排除了该问题的任何常数因子算法。<sup>[2](https://users.ece.utexas.edu/~garg/publicCompanion/chapter14-classical.html)</sup> 后来从强 [PCP 定理](https://www.edgepedia.org/zh/pcp-theorem)出发，建立了集合覆盖近似的一个紧 NP 困难性结果。<sup>[11](https://zesty.cs.uchicago.edu/articles/v011a007/)</sup>

## 最大割及其他贪心保证

最大割要求将图的顶点划分为使跨越边数最多的两部分。一种局部搜索算法——只要移动某个顶点能增大割的大小就移动它，直到不存在这样的顶点——是一个 2-近似：终止时每个顶点 a(v) 的跨越边数至少不少于非跨越边数，因此割的大小至少为 |E|/2，而最优值至多为 |E|。<sup>[1](https://people.cs.umass.edu/~mcgregor/611S24/lec18.pdf)</sup>

装箱问题——将大小至多为 1 的物品装入单位箱子——通过首次适应可得到简单的 2-近似：至多有一个箱子最终装填不足一半，因此所用箱子数至多为物品总大小的两倍，而物品总大小是最优值的下界。<sup>[4](https://people.csail.mit.edu/ghaffari/AA19/AAscript.pdf)</sup>

## 近似方案：PTAS 与 FPTAS

对某些问题，可以任意接近最优值。多项式时间近似方案（PTAS）是一个算法 A<sub>ε</sub>，对于参数 ε，它在关于输入规模的多项式时间内返回代价至多为 (1 + ε) · OPT 的解；ε 是算法的参数而非输入，因此运行时间可以任意依赖于它。若将 ε 视为输入，且时间关于 |I| 和 1/ε 均为多项式，则该方案是完全多项式时间近似方案（FPTAS）。在假设 P ≠ NP 的前提下，FPTAS 是 NP 难问题上所能期望的最好结果。<sup>[4](https://people.csail.mit.edu/ghaffari/AA19/AAscript.pdf)</sup>

**背包问题。** 0/1 背包问题在大小预算下最大化物品的总利润。精确动态规划运行时间为 O(n² p<sub>max</sub>)，其中 p<sub>max</sub> 是最大物品利润，这是伪多项式的，因为 p<sub>max</sub> 可能关于输入的比特长度为指数级。<sup>[4](https://people.csail.mit.edu/ghaffari/AA19/AAscript.pdf)</sup> FPTAS 将每个利润向下取整到 k = max{1, ⌊ε p<sub>max</sub>/n⌋} 的倍数，并对缩放后的值运行同样的动态规划。总取整损失至多为 ε · p<sub>max</sub> ≤ ε · OPT，因此返回的装箱方案价值至少为 (1 − ε) · OPT，运行时间 O(n³/ε) 关于 n 和 1/ε 均为多项式。<sup>[4](https://people.csail.mit.edu/ghaffari/AA19/AAscript.pdf)</sup>

## 近似的困难性

近似算法与表明哪些比值不可达的下界相匹配。这些结果通常借助 PCP 定理及其变体，通过从概率可检验证明到最优化问题的归约来证明；大多数不可近似性结果以 P ≠ NP 为条件，尽管该理论对某些算法类也给出无条件限制。<sup>[12](https://theory.stanford.edu/~trevisan/pcp/)</sup> 对于顶点覆盖，迪努尔与萨夫拉的 1.3606 困难性与接近比值 2 的算法形成对照，而唯一游戏猜想预测 2 事实上就是正确答案；自 1970 年代以来，该问题一直未能改进到 2 − ε 以下。<sup>[3](https://annals.math.princeton.edu/2005/162-1/p08)</sup><sup> • </sup><sup>[2](https://users.ece.utexas.edu/~garg/publicCompanion/chapter14-classical.html)</sup> 霍斯塔德（2001）证明了 Max-3-SAT 在多项式时间内不能近似到优于 7/8 + ε。<sup>[2](https://users.ece.utexas.edu/~garg/publicCompanion/chapter14-classical.html)</sup>

该领域的标准参考书包括 [维杰·瓦齐拉尼](https://www.edgepedia.org/zh/vijay-vazirani)的 *Approximation Algorithms*（Springer，2003）以及威廉姆森与施莫伊斯的 *The Design of Approximation Algorithms*（Cambridge，2011）。<sup>[13](https://cse.iitkgp.ac.in/~swagato/ApproxOnline.html)</sup>

## References

1. [Andrew McGregor, CMPSCI 611 Lecture 18: Approximation Algorithms, UMass Amherst](https://people.cs.umass.edu/~mcgregor/611S24/lec18.pdf)
2. [Vijay K. Garg, Chapter 14: Approximation Algorithms (Classical), A Systematic Approach to Algorithms, University of Texas at Austin](https://users.ece.utexas.edu/~garg/publicCompanion/chapter14-classical.html)
3. [Irit Dinur and Samuel Safra (2005). On the hardness of approximating vertex cover. Annals of Mathematics 162(1), 439–485.](https://annals.math.princeton.edu/2005/162-1/p08)
4. [Mohsen Ghaffari, Advanced Algorithms lecture notes, ETH Zurich, Fall 2019](https://people.csail.mit.edu/ghaffari/AA19/AAscript.pdf)
5. [Brennan's notes, EECS 477, University of Michigan](https://github.com/brenns10/notes/blob/master/eecs477.org)
6. [Norbert Zeh, Algorithms II, Section 9.2.2: Proof of Approximation Ratio, Dalhousie University](https://web.cs.dal.ca/~nzeh/Teaching/4113/book/greedy_approx/greedy_set_cover/approximaiton_ratio.html)
7. [Mohsen Rezaei, Lecture 1: Introduction, Vertex Cover, University of Alberta, 2011](https://webdocs.cs.ualberta.ca/~mreza/courses/Approx11/lecture1.pdf)
8. [CSE 421 Lecture 25: Approximation Algorithms, University of Washington](https://courses.cs.washington.edu/courses/cse421/24au/lectures/lecture25-approximation-A.pdf)
9. [HKU AI Lab notes: Set cover problem, greedy algorithm](https://i.cs.hku.hk/~hkual/Notes/Greedy/Set%20cover%20problem.html)
10. [Tighter inapproximability for set cover, arXiv:1612.01610](https://arxiv.org/abs/1612.01610)
11. [The Projection Games Conjecture and the NP-Hardness of ln n-Approximating Set-Cover, Theory of Computing](https://zesty.cs.uchicago.edu/articles/v011a007/)
12. [Luca Trevisan, PCP and Hardness of Approximation, Stanford CS 294](https://theory.stanford.edu/~trevisan/pcp/)
13. [Swagato Sanyal, CS60023 Approximation and Online Algorithms, IIT Kharagpur](https://cse.iitkgp.ac.in/~swagato/ApproxOnline.html)
14. [ECCC - TR04-084](https://eccc.weizmann.ac.il/eccc-reports/2004/TR04-084/index.html)

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

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › Algorithms and computational methods › Computational complexity › Complexity of database and optimization problems

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/approximation-algorithm

English original: https://www.edgepedia.org/approximation-algorithm
