# 主定理（算法分析）

主定理是算法分析中的一个结果，它给出了许多分治递推式的渐近运行时间，这些递推式具有形式 \( T(n) = aT(n/b) + f(n) \)，其中 \( a \geq 1 \) 个规模为 \( n/b \)（\( b > 1 \)）的子问题被递归求解，\( f(n) \) 是拆分与合并的非递归工作量，前提是该递推式满足其某一情形的条件。<sup>[12](https://www.cs.yale.edu/homes/aspnes/pinewiki/SolvingRecurrences.html)</sup> 该定理由乔恩·路易斯·本特利（Jon Louis Bentley）、多萝西娅·哈肯（Dorothea Haken）和詹姆斯·B·萨克斯（James B. Saxe）于1980年首次发表，并经科尔曼（Cormen）、莱瑟森（Leiserson）、里维斯特（Rivest）和斯坦（Stein）合著的教科书《算法导论》（CLRS）以“主方法”之名推广开来。<sup>[1](https://ocw.cs.pub.ro/ppcarte/lib/exe/fetch.php?media=aa%3Amaster.pdf)</sup><sup> • </sup><sup>[2](https://web.engr.oregonstate.edu/~huanlian/algorithms_course/1-datastructures/master.html)</sup>

| 关键事实 | 详情 |
|---|---|
| 递推形式 | \( T(n) = aT(n/b) + f(n) \)，其中 \( a \geq 1 \)（分支因子），\( b > 1 \)（分割因子），\( f(n) \) 为拆分加合并的工作量<sup>[2](https://web.engr.oregonstate.edu/~huanlian/algorithms_course/1-datastructures/master.html)</sup> |
| 判定量 | 将 \( f(n) \) 与 \( n^{\log_b a} \) 比较，后者是递归树叶子节点所贡献的工作量<sup>[3](https://www.cs.toronto.edu/~shaharry/csc236-summer-2025/lectures/l6-s.html)</sup> |
| 情形1（叶子主导） | 若对某个 \( \epsilon > 0 \) 有 \( f(n) = O(n^{\log_b a - \epsilon}) \)，则 \( T(n) = \Theta(n^{\log_b a}) \)<sup>[3](https://www.cs.toronto.edu/~shaharry/csc236-summer-2025/lectures/l6-s.html)</sup> |
| 情形2（平衡） | 若 \( f(n) = \Theta(n^{\log_b a}) \)，则 \( T(n) = \Theta(f(n)\log n) \)；扩展形式 \( f(n) = \Theta(n^{\log_b a}\log^k n) \) 给出 \( \Theta(n^{\log_b a}\log^{k+1} n) \)<sup>[3](https://www.cs.toronto.edu/~shaharry/csc236-summer-2025/lectures/l6-s.html)</sup><sup> • </sup><sup>[4](https://math.umd.edu/~immortal/CMSC351/notes/mastertheorem.pdf)</sup> |
| 情形3（根主导） | 若 \( f(n) = \Omega(n^{\log_b a + \epsilon}) \) 且对某个 \( c < 1 \) 满足正则条件 \( af(n/b) \leq cf(n) \)，则 \( T(n) = \Theta(f(n)) \)<sup>[3](https://www.cs.toronto.edu/~shaharry/csc236-summer-2025/lectures/l6-s.html)</sup> |
| 经典结果 | 二分查找：\( T(n) = T(n/2) + O(1) \in O(\log n) \)；归并排序：\( T(n) = 2T(n/2) + O(n) \in O(n\log n) \)<sup>[5](https://chalmersgu-data-structure-courses.github.io/dsabook/html/section-7.6.html)</sup> |
| 主要推广 | 阿克拉–巴齐方法（1998）处理子问题规模不等的递推式，其覆盖范围是主方法所覆盖递推式集合的超集<sup>[1](https://ocw.cs.pub.ro/ppcarte/lib/exe/fetch.php?media=aa%3Amaster.pdf)</sup> |

## 递推式及其参数

分治算法将规模为 \( n \) 的输入分割为 \( b \) 个大致相等且互不重叠的部分，递归求解其中的 \( a \) 个，并在递归调用之外花费 \( f(n) \) 的工作量来分割输入并合并部分解。因此运行时间满足 \( T(n) = aT(n/b) + f(n) \)。参数 \( a \) 是递归树的分支因子，必须满足 \( a \geq 1 \)；\( b \) 是问题缩小的因子，必须满足 \( b > 1 \)，否则递归将永不终止。两者均为常数。在归并排序中，\( a = b = 2 \)，\( f(n) = n \)；在二分查找中，\( a = 1 \)，\( b = 2 \)，\( f(n) = 1 \)，因为只搜索两个半区之一。<sup>[2](https://web.engr.oregonstate.edu/~huanlian/algorithms_course/1-datastructures/master.html)</sup><sup> • </sup><sup>[6](https://courses.cs.washington.edu/courses/cse417/25au/readings/divide_and_conquer.html)</sup>

当 \( n \) 不能被 \( b \) 整除时出现的向下取整和向上取整，对渐近性影响可忽略不计，通常被略去。<sup>[3](https://www.cs.toronto.edu/~shaharry/csc236-summer-2025/lectures/l6-s.html)</sup>

## 递归树论证

该定理通过将递归树每一层的工作量求和而导出。第0层做 \( f(n) \) 的工作；第 \( h \) 层有 \( a^h \) 个节点，每个规模为 \( n/b^h \)，总计 \( a^h f(n/b^h) \)。树的高度为 \( \log_b n \)，最后一层包含 \( a^{\log_b n} = n^{\log_b a} \) 个叶子，每个贡献常数工作量，因此叶子合计做 \( \Theta(n^{\log_b a}) \) 的工作。<sup>[2](https://web.engr.oregonstate.edu/~huanlian/algorithms_course/1-datastructures/master.html)</sup><sup> • </sup><sup>[3](https://www.cs.toronto.edu/~shaharry/csc236-summer-2025/lectures/l6-s.html)</sup>

三种情形问的是树的哪一侧占主导。当沿树向下移动时，子问题数量呈指数增长，而每个子问题的工作量呈指数缩减；临界指数 \( \log_b a \) 正是这两种速率相平衡的点。若每层工作量向叶子方向呈几何级数增长（情形1），则叶子主导，\( T(n) = \Theta(n^{\log_b a}) \)。<sup>[13](https://courses.csail.mit.edu/6.006/spring11/rec/rec08.pdf)</sup> 若每层工作量保持在一个常数因子以内（情形2），则全部 \( \log_b n \) 层贡献相当，并附加一个对数因子。若每层工作量向叶子方向呈几何级数递减（情形3），则根主导总工作量，但须满足正则条件 \( af(n/b) \leq cf(n) \)（对某个 \( c < 1 \) 及所有充分大的 \( n \)），该条件保证了这种几何递减。<sup>[3](https://www.cs.toronto.edu/~shaharry/csc236-summer-2025/lectures/l6-s.html)</sup><sup> • </sup><sup>[4](https://math.umd.edu/~immortal/CMSC351/notes/mastertheorem.pdf)</sup><sup> • </sup><sup>[14](https://www.cs.cornell.edu/courses/cs3110/2010sp/Lectures/lec20.html)</sup>

情形1和情形3中的 \( \epsilon \) 要求一个多项式间隙：\( f(n) = O(n^{\log_b a - \epsilon}) \) 意味着 \( f \) 比 \( n^{\log_b a} \) 小至少 \( n^{\epsilon} \) 倍。例如 \( n^{1.9} = O(n^{2-\epsilon}) \) 取 \( \epsilon = 0.01 \)，但 \( n^2/\log n \) 对任何 \( \epsilon > 0 \) 都不是 \( O(n^{2-\epsilon}) \)，因此对这样的 \( f \) 直接套用情形1会失败。<sup>[3](https://www.cs.toronto.edu/~shaharry/csc236-summer-2025/lectures/l6-s.html)</sup>

## 实例演算

**二分查找。** \( T(n) = T(n/2) + O(1) \)：此处 \( a = 1 \)，\( b = 2 \)，在多项式工作量形式 \( f(n) = O(n^k) \) 中 \( k = 0 \)。由于 \( a = b^k \)，适用情形2，得 \( T(n) \in O(n^k \log n) = O(\log n) \)。<sup>[5](https://chalmersgu-data-structure-courses.github.io/dsabook/html/section-7.6.html)</sup>

**归并排序。** \( T(n) = 2T(n/2) + O(n) \)：\( a = 2 \)，\( b = 2 \)，\( k = 1 \)，同样 \( a = b^k \)，故 \( T(n) \in O(n \log n) \)。<sup>[5](https://chalmersgu-data-structure-courses.github.io/dsabook/html/section-7.6.html)</sup>

**子问题过多，工作量无法支撑。** \( T(n) = 3T(n/2) + O(n) \)：\( a = 3 > b^k = 2 \)，故递归工作量主导，\( T(n) \in O(n^{\log_2 3}) \approx O(n^{1.6}) \)。<sup>[5](https://chalmersgu-data-structure-courses.github.io/dsabook/html/section-7.6.html)</sup>

**合并代价高昂。** \( T(n) = 3T(n/2) + O(n^2) \)：\( a = 3 < b^k = 4 \)，故额外工作量主导，\( T(n) \in O(n^2) \)。<sup>[5](https://chalmersgu-data-structure-courses.github.io/dsabook/html/section-7.6.html)</sup>

**工作量中含对数因子。** 对于 \( T(n) = 9T(n/3) + n^2 \lg n \)，\( \log_b a = \log_3 9 = 2 \) 与 \( f(n) \) 的指数匹配，故取 \( k = 1 \) 的扩展情形2给出 \( T(n) = \Theta(n^2 \lg^2 n) \)。<sup>[4](https://math.umd.edu/~immortal/CMSC351/notes/mastertheorem.pdf)</sup>

## 适用范围与局限

该定理仅适用于标准形式且 \( a \)、\( b \) 为常数的递推式。它不适用于 \( T(n) = 2T(n/4) + 3T(n/2) + n \)，因为形式不对；严格来说也不适用于 \( k \) 路归并排序 \( T(n) = kT(n/k) + n\log k \)，当 \( k \) 是变量而非常数时，尽管该递推式在其他方面符合情形2。<sup>[4](https://math.umd.edu/~immortal/CMSC351/notes/mastertheorem.pdf)</sup><sup> • </sup><sup>[2](https://web.engr.oregonstate.edu/~huanlian/algorithms_course/1-datastructures/master.html)</sup> 该定理也不能仅凭部分信息套用：对于 \( T(n) = 2T(n/4) + f(n) \)，仅知道 \( f(n) = O(n^2) \) 并不能触发情形1，因为 \( \log_b a = 0.5 \) 并不大于2。<sup>[4](https://math.umd.edu/~immortal/CMSC351/notes/mastertheorem.pdf)</sup>

CLRS不同版本中的表述有所变化。递推式 \( T(n) = 2T(n/2) + n\log n \) 在第3版所述的主方法中未被覆盖，但第4版将情形2扩展到工作量函数与 \( n^{\log_b a} \) 相差一个对数因子的情形，该递推式在其中得到覆盖。<sup>[7](https://github.com/pl3onasm/CLRS/blob/main/algorithms/theory/recurrences/master-method.md)</sup>

## 推广

1998年，[穆罕默德·阿克拉](https://www.edgepedia.org/zh/mohamad-akra)（Mohamad Akra）和卢埃·巴齐（Louay Bazzi）提出了一种更一般的递推关系方法，覆盖子问题规模不等的情形，形式为 \( T(x) = \sum_i a_i T(b_i x + h_i(x)) + g(x) \)；它处理的是主方法所覆盖递推式的超集。<sup>[1](https://ocw.cs.pub.ro/ppcarte/lib/exe/fetch.php?media=aa%3Amaster.pdf)</sup> 对于含有多个不同规模的递归项的递推式，例如 \( T(n) = \tfrac14 T(n/16) + \tfrac13 T(3n/5) + 4T(n/100) + 10T(n/300) + n^2 \)，多规模递推式的主型定理已被建立。<sup>[8](https://arxiv.org/abs/cs/0101011)</sup>

离散性带来了自身的影响。迈克尔·德尔莫塔（Michael Drmota）和沃伊切赫·什潘科夫斯基（Wojciech Szpankowski）证明了离散分治递推式的主定理，其中向下取整函数引入了传统定理以及阿克拉和巴齐（他们研究的是连续版本）未能刻画的振荡。<sup>[9](https://epubs.siam.org/doi/10.1137/1.9781611973082.28)</sup> 奥利维耶·加雷（Olivier Garet）于2019年给出了离散递推式 \( X_n = a_n + \sum_j b_j X_{\lfloor p_j n \rfloor} \) 的主定理，该定理对驱动序列 \( (a_n) \) 无需任何正则性或单调性假设，甚至允许来自随机算法的随机 \( (a_n) \)。<sup>[10](https://arxiv.org/abs/1902.10600)</sup> [马萨诸塞大学波士顿分校](https://www.edgepedia.org/zh/university-of-massachusetts-boston)的数学家卡尔·D·奥夫纳（Carl D. Offner）于2025年发表了他所描述的分治递推式主定理的一般、最佳可能形式，追溯了从最初的本特利–哈肯–萨克斯定理经阿克拉、巴齐和莱顿（Leighton）的传承脉络。<sup>[11](https://arxiv.org/abs/2507.16064)</sup>

## References

1. [Jon Louis Bentley, Dorothea Haken, and James B. Saxe (1980), "A General Method for Solving Divide-and-Conquer Recurrences", ACM SIGACT News 12.3, pp. 36–44; as cited in "The Master Method" lecture notes, Politehnica University of Bucharest OCW](https://ocw.cs.pub.ro/ppcarte/lib/exe/fetch.php?media=aa%3Amaster.pdf)
2. [1.9 Master Theorem and Summary of Common Recurrences, Huan Li, Oregon State University](https://web.engr.oregonstate.edu/~huanlian/algorithms_course/1-datastructures/master.html)
3. [CSC236 Summer 2025, Lecture 06: Recurrences 2, University of Toronto](https://www.cs.toronto.edu/~shaharry/csc236-summer-2025/lectures/l6-s.html)
4. [CMSC 351: The Master Theorem, lecture notes, University of Maryland](https://math.umd.edu/~immortal/CMSC351/notes/mastertheorem.pdf)
5. [DSABook – Deriving the Master theorem, Chalmers University of Technology](https://chalmersgu-data-structure-courses.github.io/dsabook/html/section-7.6.html)
6. [CSE417 – Divide and Conquer, University of Washington](https://courses.cs.washington.edu/courses/cse417/25au/readings/divide_and_conquer.html)
7. [The master method (CLRS recurrences notes), pl3onasm/CLRS on GitHub](https://github.com/pl3onasm/CLRS/blob/main/algorithms/theory/recurrences/master-method.md)
8. [Multiple-Size Divide-and-Conquer Recurrences, arXiv:cs/0101011](https://arxiv.org/abs/cs/0101011)
9. [Michael Drmota and Wojciech Szpankowski, "A Master Theorem for Discrete Divide and Conquer Recurrences", SODA 2011, pp. 342–361](https://epubs.siam.org/doi/10.1137/1.9781611973082.28)
10. [Olivier Garet (2019), "A simple Master Theorem for Discrete Divide and Conquer Recurrences", arXiv:1902.10600](https://arxiv.org/abs/1902.10600)
11. [Carl D. Offner (2025), "A Best Possible General Form of the Master Theorem for Divide-and-Conquer Recurrences", arXiv:2507.16064](https://arxiv.org/abs/2507.16064)
12. [SolvingRecurrences](https://www.cs.yale.edu/homes/aspnes/pinewiki/SolvingRecurrences.html)
13. [courses.csail.mit.edu](https://courses.csail.mit.edu/6.006/spring11/rec/rec08.pdf)
14. [Lecture 19: Recursion Trees and the Master Method](https://www.cs.cornell.edu/courses/cs3110/2010sp/Lectures/lec20.html)

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

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › Algorithms and computational methods › Algorithms overview

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/master-theorem-analysis-of-algorithms

English original: https://www.edgepedia.org/master-theorem-analysis-of-algorithms
