# 计算复杂性

计算复杂性是理论计算机科学的一个分支，它根据求解计算问题所需的资源（如时间和内存）对计算问题进行分类，尤其要区分那些可以用合理资源解决的问题与那些似乎需要超出已有或可想象的计算机能力的资源才能解决的问题。<sup>[1](https://theory.stanford.edu/~trevisan/cs278-04/)</sup> 可计算性理论追问一个问题究竟能否被解决，而复杂性理论则追问在已知问题可解的前提下，它能被多高效地解决。<sup>[2](https://cs.lmu.edu/~ray/notes/complexitytheory/)</sup>

| 关键事实 | 细节 |
|---|---|
| 所度量的资源 | 时间以基本步数（图灵机上的状态转移）计算；空间以所使用的纸带单元或内存位置计算，不包括输入本身<sup>[2](https://cs.lmu.edu/~ray/notes/complexitytheory/)</sup> |
| 最坏情况度量 | 机器 M 的时间复杂性 \( t_{M}(n) \) 是所有长度为 n 的输入上的最大步数<sup>[3](https://plato.stanford.edu/archives/fall2021/entries/computational-complexity/)</sup> |
| 渐近比较 | 若存在常数 k 和 N，使得对所有 n ≥ N 都有 f(n) ≤ k · g(n)，则函数 f 为 O(g(n))；常数因子和增长较慢的项被忽略<sup>[4](https://pages.cs.wisc.edu/~siff/CS367/Notes/complexity.html)</sup> |
| 核心类 | P 是所有 k 对应的 \( \textbf{TIME}(n^k) \) 的并集；PSPACE 对空间作类似定义；NP、BPP 和 BQP 则通过改变机器模型或接受条件而产生<sup>[3](https://plato.stanford.edu/archives/fall2021/entries/computational-complexity/)</sup> |
| 核心未解问题 | P 与 NP 问题由斯蒂芬·库克（Stephen Cook）和列昂尼德·莱文（Leonid Levin）于 1971 年独立提出，它追问：是否每一个解易于检验的问题也易于求解；它是七个千禧年大奖难题之一，每项奖金一百万美元<sup>[5](https://www.claymath.org/millennium/p-vs-np/)</sup><sup> • </sup><sup>[6](https://www.claymath.org/Millennium%20Problems/)</sup> |
| 已知包含关系 | \( \textsf{LOGSPACE} \subseteq \textsf{P} \subseteq \textsf{NP} \subseteq \textsf{PSPACE} \)；对角化论证表明第一个类真包含于最后一个类，但没有任何相邻的包含关系被证明为真包含<sup>[7](https://www.claymath.org/wp-content/uploads/2022/02/MPPc.pdf)</sup> |
| 证明障碍 | 任何 P ≠ NP 的证明都必须克服相对化障碍与自然证明障碍，而阿伦森（Aaronson）和维格德森（Wigderson）于 2008 年表明，第三种障碍——代数化——同样适用<sup>[8](https://eccc.weizmann.ac.il/eccc-reports/2008/TR08-005/Paper.pdf)</sup> |

## 度量资源

复杂性理论需要一个简单的计算模型，以及一种统计该模型所耗资源的方法。传统模型是[图灵机](https://www.edgepedia.org/zh/turing-machine)、布尔电路和交互式证明系统，并有并行、概率或量子等变体。<sup>[2](https://cs.lmu.edu/~ray/notes/complexitytheory/)</sup> 在图灵机上，时间是状态转移的次数，空间是访问或写入的纸带单元数，不包括输入本身。<sup>[2](https://cs.lmu.edu/~ray/notes/complexitytheory/)</sup><sup> • </sup><sup>[3](https://plato.stanford.edu/archives/fall2021/entries/computational-complexity/)</sup>

**最坏情况分析。** 机器在单个输入上的运行时间，通过对该长度所有输入取最大值，转化为输入长度的函数：\( t_{M}(n) = \max \{ time_{M}(x) : \lvert x \rvert = n \} \)。空间复杂性 \( s_{M}(n) \) 以同样方式定义。<sup>[3](https://plato.stanford.edu/archives/fall2021/entries/computational-complexity/)</sup> 由于分析是最坏情况的，一个大 O 界就是一种保证：算法在给定规模的每一个输入上都会在所述时间内完成。<sup>[9](https://homes.cs.ru.ac.za/philip/Courses/CS2-ToC/CS202_2020_Theory_of_Computing-v1.1.pdf)</sup>

**渐近增长阶。** 绝对运行时间被有意忽略，因为它们随硬件而变化；一台快一倍的计算机使 6n 步的算法表现得与 3n 步的算法完全相同。<sup>[2](https://cs.lmu.edu/~ray/notes/complexitytheory/)</sup> 取而代之的是按增长阶比较函数：\( O(f(n)) \) 是所有在渐近意义下以 f(n) 的某个常数倍为上界的函数构成的集合。例如，每个常数函数、\( \log(n) \)、n 以及 \( c_1 \cdot n^2 + c_2 \) 都属于 \( O(n^2) \)，而 \( \frac{1}{1000}n^3 \) 不属于。<sup>[3](https://plato.stanford.edu/archives/fall2021/entries/computational-complexity/)</sup> 一个问题的复杂性于是就是判定它的最高效算法的复杂性。<sup>[3](https://plato.stanford.edu/archives/fall2021/entries/computational-complexity/)</sup>

## 复杂性类

复杂性类是在固定计算模型下，在给定时间或空间界内可判定的问题所构成的集合。<sup>[3](https://plato.stanford.edu/archives/fall2021/entries/computational-complexity/)</sup> 类 \( \textbf{TIME}(f(n)) \) 收集时间复杂性为 f(n) 的问题；P 是所有自然数 k 对应的 \( \textbf{TIME}(n^k) \) 的并集，因此它包含每一个可由图灵机在多项式时间内实现判定算法的问题。\( \textbf{SPACE}(f(n)) \) 和 PSPACE 对内存作类似定义。<sup>[3](https://plato.stanford.edu/archives/fall2021/entries/computational-complexity/)</sup>

其他类则改变底层机器或其接受规则。NP、BPP（有界错误概率多项式时间）和 BQP（有界错误量子多项式时间）都是这样得到的。<sup>[3](https://plato.stanford.edu/archives/fall2021/entries/computational-complexity/)</sup> 模型的选择并不像看上去那么重要：任何合理的计算模型，只要不涉及指数级并行，都可以由图灵机在多项式时间内模拟。<sup>[10](https://algs4.cs.princeton.edu/66intractability/)</sup>

当理查德·斯特恩斯（Richard Stearns）与尤里·哈特马尼斯（Juri Hartmanis）和菲利普·刘易斯（Philip Lewis）合作时，他决定只计算工作纸带上的空间，把输入放在另一条纸带上，理论的空间一侧由此转向实践。这一决定使次线性空间有了意义，开启了对 log n 空间的研究；萨维奇（Savitch）随后在他们的技术基础上表明，非确定性与确定性多项式空间是同一个类。<sup>[11](https://amturing.acm.org/pdf/StearnsTuringTranscript.pdf)</sup>

## P 与 NP 及 NP 完全性

该领域的核心问题追问类 P 与 NP 是否相等：如果一个问题的解可以被快速检验，那么这个解是否也能被快速找到？[斯蒂芬·库克](https://www.edgepedia.org/zh/stephen-cook)和[列昂尼德·莱文](https://www.edgepedia.org/zh/leonid-levin)于 1971 年独立地表述了这个问题。<sup>[5](https://www.claymath.org/millennium/p-vs-np/)</sup> 库克当年在 ACM STOC 会议上发表了《定理证明过程的复杂性》，这篇论文引入了如今被称为 NP 完全性理论的内容。<sup>[12](https://amturing.acm.org/pdf/CookTuringTranscript.pdf)</sup> 库克-莱文定理指出，SAT，即布尔可满足性问题，是 NP 完全的。<sup>[13](https://citeseerx.ist.psu.edu/document?doi=ccfd795cfc2124e7c0d37b262a67486258cd8a8e&repid=rep1&type=pdf)</sup>

NP 完全性为研究者提供了一种论证许多问题本质上难以求解的方法，尽管困难性的证明仍超出当前知识：只要任何一个 NP 完全问题有多项式时间算法，所有 NP 完全问题就都有。<sup>[14](https://epubs.siam.org/doi/10.1137/1036051)</sup> 该理论也使研究避开没有希望的方向。<sup>[10](https://algs4.cs.princeton.edu/66intractability/)</sup> 多数复杂性理论家相信 P ≠ NP，部分原因是数十年来成千上万的程序员和工程师寻求 NP 完全问题的有效算法而未获成功，也因为密码学方案的安全性以困难性假设为前提。<sup>[15](https://www.claymath.org/wp-content/uploads/2022/06/pvsnp.pdf)</sup>

信念与证明之间的鸿沟很大。求解 3-SAT 的算法已证明的最好上界约为 \( 1.5^n \)，其中 n 是变量数，远高于多项式。<sup>[15](https://www.claymath.org/wp-content/uploads/2022/06/pvsnp.pdf)</sup> 在下界一侧，香农（Shannon）于 1949 年证明几乎所有的布尔函数都需要至少 \( 2^n/n \) 个门的电路，但他的计数论证无法为 NP 中的问题证明下界；对于无限制电路和显式给定的函数，已证明的最好下界仅为约 4n。<sup>[7](https://www.claymath.org/wp-content/uploads/2022/02/MPPc.pdf)</sup>

## 证明的障碍

三个形式化结果解释了为什么标准技术不足以解决 P 与 NP 问题。对角化及其相对化形式无法分离这些类，因为存在使 P = NP 的谕示，也存在使 P ≠ NP 的谕示。拉兹博罗夫（Razborov）和鲁迪赫（Rudich）的自然证明障碍表明，宽泛的组合下界论证也会破坏人们相信存在的伪随机函数；假设这类生成器存在，那么一般电路下界的自然证明将产生比任何已知算法都更好的因数分解算法。<sup>[7](https://www.claymath.org/wp-content/uploads/2022/02/MPPc.pdf)</sup><sup> • </sup><sup>[16](https://math.uchicago.edu/~may/REU2016/REUPapers/Vale.pdf)</sup> 2008 年，麻省理工学院的斯科特·阿伦森和[高等研究院](https://www.edgepedia.org/zh/institute-for-advanced-study)的[阿维·维格德森](https://www.edgepedia.org/zh/avi-wigderson)引入了代数化，这是第三种障碍：基于算术化的已知非相对化结果，如 IP = PSPACE，确实会代数化，而几乎所有重大未解问题，包括 P 与 NP 问题，都将需要非代数化的技术。<sup>[8](https://eccc.weizmann.ac.il/eccc-reports/2008/TR08-005/Paper.pdf)</sup>

这些障碍最好被理解为对特定证明技术的限制，而非对数学本身的限制：存在超越每一种障碍的结果。<sup>[17](https://eccc.weizmann.ac.il/report/2017/004/download/)</sup> 瑞安·威廉姆斯（Ryan Williams）和凯坦·穆尔穆莱（Ketan Mulmuley）最近的工作以不同方式暗示了不可能性证明与算法之间的对偶性。<sup>[18](https://eccc.weizmann.ac.il/report/2017/004/)</sup>

## 理论与实践

多项式时间是该领域对易处理性的工作定义，因为其中涉及的常数通常足够小，多项式时间算法能扩展到巨大的问题。<sup>[10](https://algs4.cs.princeton.edu/66intractability/)</sup> 然而，最坏情况的视角并不能捕捉一切。布尔可满足性是 NP 完全的，但现代 SAT 求解器能处理验证、综合和规划中出现的、含有数百万变量和子句的公式；当没有可用的精确高效算法时，实践者也会求助于启发式搜索、松弛、近似和随机化。<sup>[19](https://www.cs.princeton.edu/courses/archive/spring23/cosIW04/)</sup>

更精细的问题仍然活跃。平均情况复杂性理论追问 NP 问题在现实输入分布下是否困难；因帕利亚佐（Impagliazzo）和莱文的完全性结果表明，如果某个特定的 NP 问题在均匀分布下平均容易，那么所有 NP 问题在所有可采样分布下都平均容易，但将该理论应用于自然的分布问题仍然悬而未决。<sup>[20](https://arxiv.org/abs/cs/0606037)</sup> [细粒度复杂性](https://www.edgepedia.org/zh/fine-grained-complexity)研究条件下界，用以区分 P 内例如二次与近乎二次的运行时间。<sup>[21](https://arxiv.org/abs/2110.10283)</sup>

## References

1. [Luca Trevisan, CS 278 Computational Complexity, Stanford University](https://theory.stanford.edu/~trevisan/cs278-04/)
2. [Ray Toal, Complexity Theory notes, Loyola Marymount University](https://cs.lmu.edu/~ray/notes/complexitytheory/)
3. [Computational Complexity Theory, Stanford Encyclopedia of Philosophy (Fall 2021)](https://plato.stanford.edu/archives/fall2021/entries/computational-complexity/)
4. [Notes on Computational Complexity, CS 367, University of Wisconsin](https://pages.cs.wisc.edu/~siff/CS367/Notes/complexity.html)
5. [P vs NP, Clay Mathematics Institute](https://www.claymath.org/millennium/p-vs-np/)
6. [The Millennium Prize Problems, Clay Mathematics Institute](https://www.claymath.org/Millennium%20Problems/)
7. [Stephen Cook, "The P Versus NP Problem," in The Millennium Prize Problems, Clay Mathematics Institute](https://www.claymath.org/wp-content/uploads/2022/02/MPPc.pdf)
8. [Scott Aaronson and Avi Wigderson, "Algebrization: A New Barrier in Complexity Theory," ECCC TR08-005](https://eccc.weizmann.ac.il/eccc-reports/2008/TR08-005/Paper.pdf)
9. [Theory of Computing course notes, University of South Africa/CS202](https://homes.cs.ru.ac.za/philip/Courses/CS2-ToC/CS202_2020_Theory_of_Computing-v1.1.pdf)
10. [Intractability, Algorithms, Princeton University](https://algs4.cs.princeton.edu/66intractability/)
11. [A. M. Turing Award Oral History Interview with Richard Stearns, ACM](https://amturing.acm.org/pdf/StearnsTuringTranscript.pdf)
12. [A. M. Turing Award Oral History Interview with Stephen Cook, ACM](https://amturing.acm.org/pdf/CookTuringTranscript.pdf)
13. [Complexity Theory lecture notes (Cook-Levin theorem), CiteSeerX](https://citeseerx.ist.psu.edu/document?doi=ccfd795cfc2124e7c0d37b262a67486258cd8a8e&repid=rep1&type=pdf)
14. [Ronald V. Book, "Relativizations of the P =? NP and Other Problems," SIAM Review](https://epubs.siam.org/doi/10.1137/1036051)
15. [Stephen Cook, "The P Versus NP Problem," official Clay Mathematics Institute problem description](https://www.claymath.org/wp-content/uploads/2022/06/pvsnp.pdf)
16. [Arthur Vale, "Barriers in Complexity Theory," University of Chicago REU](https://math.uchicago.edu/~may/REU2016/REUPapers/Vale.pdf)
17. [Scott Aaronson, "P=?NP," ECCC TR17-004 (full text)](https://eccc.weizmann.ac.il/report/2017/004/download/)
18. [Scott Aaronson, "P=?NP," ECCC TR17-004](https://eccc.weizmann.ac.il/report/2017/004/)
19. [COS IW 04: Practical Solutions to Intractable Problems, Princeton University](https://www.cs.princeton.edu/courses/archive/spring23/cosIW04/)
20. [Andrej Bogdanov and Luca Trevisan, "Average-Case Complexity," arXiv](https://arxiv.org/abs/cs/0606037)
21. [Fine-Grained Complexity Theory: Conditional Lower Bounds for Computational Geometry, arXiv](https://arxiv.org/abs/2110.10283)

---
*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 › Classical complexity classes

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/computational-complexity

English original: https://www.edgepedia.org/computational-complexity
