# 竞争分析（在线算法）

竞争分析是一种评估在线算法的方法。在线算法必须在每个请求到达时做出不可撤销的决策，且不知道未来的请求；竞争分析通过比较在线算法在每个输入上的代价与最优离线算法的代价来评价其性能，而最优离线算法事先知道整个输入。若一个在线算法的代价在每条请求序列上至多是最优解代价的 c 倍加上一个常数，则称其为 c-竞争的；满足条件的最小 c 值即为其竞争比。该框架由当时均任职于 AT&T 贝尔实验室的丹尼尔·D·斯利特（Daniel D. Sleator）与[罗伯特·E·塔扬](https://www.edgepedia.org/zh/robert-e-tarjan)（Robert E. Tarjan）在 1985 年的论文《列表更新与分页规则的摊销效率》中提出。<sup>[1](https://dblp.org/rec/journals/cacm/SleatorT85.html)</sup><sup> • </sup><sup>[2](https://www.cs.cmu.edu/~sleator/papers/amortized-efficiency.pdf)</sup>

| 关键事实 | 详情 |
|---|---|
| 定义 | 对于最小化问题，若对所有请求序列 I 均有 Alg(I) ≤ c · Opt(I) + b（b 为常数），则算法 Alg 是 c-竞争的；若 b = 0，则称该算法是严格 c-竞争的<sup>[3](https://www.cs.toronto.edu/~bor/2421f19/papers/boyar-survey.pdf)</sup> |
| 起源 | 由斯利特与塔扬于 1985 年提出，发表于《ACM通讯》第 28 卷第 2 期，第 202–208 页<sup>[1](https://dblp.org/rec/journals/cacm/SleatorT85.html)</sup> |
| 列表更新结果 | 当访问第 i 个元素的代价为 Θ(i) 时，移至最前规则的摊销运行时间在最优离线算法的 2 倍因子之内；交换规则与频率计数规则不具备这一性质<sup>[2](https://www.cs.cmu.edu/~sleator/papers/amortized-efficiency.pdf)</sup> |
| 分页结果 | 对于大小为 k 的缓存，LRU 与 FIFO 均为 k-竞争的，且没有任何确定性在线分页算法能优于竞争比 k<sup>[4](https://templeton.host/tech-tree/online-algorithms/)</sup> |
| 随机化 | 面对自适应对手时，没有任何随机化分页算法能优于 k-竞争；无感知对手是随机化分析的标准模型<sup>[5](https://ac.informatik.uni-freiburg.de/teaching/ws16_17/algo1617/pdf/09_Online_p2.pdf)</sup><sup> • </sup><sup>[6](https://www.sciencedirect.com/science/article/abs/pii/S1574013709000197)</sup> |
| 已知局限 | 竞争分析是一种最坏情况度量，有时无法区分实践中质量不同的算法<sup>[7](https://arxiv.org/abs/1106.6136)</sup> |

## 模型

在线算法求解的是一类优化问题，其输入为有限的请求序列，每次到达一个请求。算法在收到请求时必须做出不可撤销的决策，通常不知道未来的请求，试图最小化或最大化某个目标函数。竞争分析将算法的代价与最优离线算法的代价进行比较，后者在行动之前就能看到整个序列；在所有输入上的最坏情况比值即为竞争比。<sup>[3](https://www.cs.toronto.edu/~bor/2421f19/papers/boyar-survey.pdf)</sup><sup> • </sup><sup>[8](https://mediatum.ub.tum.de/doc/1580033/document.pdf)</sup>

该框架基于三条假设：输入是对抗性的，决策是不可撤销的，在线算法在请求到达之前对其一无所知。<sup>[9](https://imada.sdu.dk/u/lenemf/Research/adviceSurvey.pdf)</sup> 由于该度量是最坏情况的，可以设想输入由一个了解该算法的恶意对手生成。对于随机化算法，对手模型至关重要：无感知对手知道算法但不知道其抛硬币的结果，且必须事先固定请求序列；而自适应对手在观察到每次决策之后才选择下一个请求。对手按强度排序为：无感知对手、在线自适应对手、离线自适应对手；针对无感知对手的下界对更强的对手同样成立。<sup>[3](https://www.cs.toronto.edu/~bor/2421f19/papers/boyar-survey.pdf)</sup><sup> • </sup><sup>[5](https://ac.informatik.uni-freiburg.de/teaching/ws16_17/algo1617/pdf/09_Online_p2.pdf)</sup>

## 奠基性结果

斯利特与塔扬运用摊销复杂度分析了两个问题，该方法结合了最坏情况分析与平均情况分析的要素。<sup>[2](https://www.cs.cmu.edu/~sleator/papers/amortized-efficiency.pdf)</sup> 对于列表更新问题——从线性表前端访问第 i 个元素需要 Θ(i) 时间——他们证明了移至最前规则的摊销运行时间在最优离线算法的 2 倍因子之内，因此任何算法，无论在线还是离线，在任何序列上都无法以超过常数因子的幅度胜过它。其他自然的启发式规则，如交换规则与频率计数规则，不具备这种近似最优性；该结果可推广到任何凸访问代价函数。<sup>[2](https://www.cs.cmu.edu/~sleator/papers/amortized-efficiency.pdf)</sup>

对于分页问题——其访问代价不是凸的——与移至最前相对应的规则是最近最少使用（LRU）替换策略。LRU 并不在离线最优算法（贝拉迪的 MIN 算法）的常数因子之内，但其摊销代价与最优解的差距因子取决于快速存储器的大小，且没有在线分页算法具有更好的摊销性能。<sup>[10](https://www.cs.cmu.edu/~sleator/papers/Amortized-Efficiency.htm)</sup> 在后来的标准表述中，对于大小为 k 的缓存，LRU 与 FIFO 均为 k-竞争的，与确定性下界相符：没有任何确定性在线分页算法能优于竞争比 k。<sup>[4](https://templeton.host/tech-tree/online-algorithms/)</sup>

## 随机化与对手

随机化有助于对抗无感知对手，但对自适应对手无效。采用与确定性算法相同的论证可知，面对自适应对手时，没有任何随机化分页算法能优于 k-竞争。<sup>[5](https://ac.informatik.uni-freiburg.de/teaching/ws16_17/algo1617/pdf/09_Online_p2.pdf)</sup> 本-戴维（Ben-David）及其合作者的一项一般性结果表明，在在线情形下，没有任何随机化算法能针对自适应对手取得优于确定性算法所能达到的竞争比。<sup>[11](https://cmualgos.github.io/2018/10/24/online.html)</sup> 面对无感知对手——这已成为分析随机化在线算法的标准模型——则可能获得更强的保证；然而，对于 k-服务器问题，存在 (k+1) 点度量空间，其中每个随机化算法的竞争比均为 Ω(log² k)，因此 O(log k) 的保证并非在每个度量空间中都成立。<sup>[6](https://www.sciencedirect.com/science/article/abs/pii/S1574013709000197)</sup><sup> • </sup><sup>[18](https://arxiv.org/abs/2211.05753)</sup>

## 批评与替代度量

对竞争分析的核心批评在于：比较的对象是一个具有完美预见能力的过于强大的对手，这可能导致极为悲观的结果，而且该度量有时无法区分实践中质量不同的算法。<sup>[12](https://lacuna.tiptreesystems.com/direction/reconstructing-high-fidelity-images-with-learned-structural-priors/txn_85688c100ed649e6bfb691acb2a450c6)</sup><sup> • </sup><sup>[7](https://arxiv.org/abs/1106.6136)</sup> 学界提出了若干替代性能度量，包括最大/最大比、随机顺序比、双射分析和相对最差顺序分析。在三个共线点上的两服务器问题的系统性比较中，这些度量对贪心算法、双重覆盖和惰性双重覆盖给出了不同的排序：按最大/最大比和双射分析，贪心在三者中最佳；而在其他度量下，双重覆盖与惰性双重覆盖更优。<sup>[13](https://arxiv.org/abs/0806.0983)</sup>

**资源增强**通过赋予在线算法相对于离线对手的轻微物理或计算优势来放松平等比较，例如处理器速度为离线对手的 1 + ε 倍、更大的内存缓冲区或额外容量。某些在同等速度下竞争比无界的优化目标——尤其是调度中的总流动时间或平均流动时间——在任意小的速度增强下即变为 O(1)-竞争的。<sup>[12](https://lacuna.tiptreesystems.com/direction/reconstructing-high-fidelity-images-with-learned-structural-priors/txn_85688c100ed649e6bfb691acb2a450c6)</sup><sup> • </sup><sup>[14](https://senior-stack.uz/Roadmap/Data/datastructures-and-algorithms/25-online-algorithms/01-competitive-analysis/professional/)</sup>

**建议复杂度**直接量化第三条假设：带建议的在线算法从一个知道整个序列的可信预言机处接收若干比特关于请求序列的信息，核心问题是获得竞争比 c 所需且充分的比特数是多少。建议与随机化之间存在紧密联系；对于许多在线问题，b 比特建议可以转化为一个 (c · 2<sup>b</sup>)-竞争的随机化算法。<sup>[9](https://imada.sdu.dk/u/lenemf/Research/adviceSurvey.pdf)</sup><sup> • </sup><sup>[3](https://www.cs.toronto.edu/~bor/2421f19/papers/boyar-survey.pdf)</sup>

**学习增强算法**用机器学习预测替代预言机。对于滑雪租赁和非透视作业调度等经典问题，已设计出对预测器性能不敏感、随预测改善而提升、且在预测较差时性能不会大幅下降的算法。<sup>[15](https://arxiv.org/abs/2407.17712)</sup>

## 应用

竞争分析适用于一切在流式输入上做决策的场景，包括分组调度和拥塞控制等网络问题、操作系统中的缓存与分页，以及在线调度。<sup>[4](https://templeton.host/tech-tree/online-algorithms/)</sup> 它还被推广到易故障机器，其中系统内最长、系统内最短、最大处理时间和最短处理时间等调度算法已在已完成负载、待处理负载和延迟等指标上进行了比较，并利用资源增强来实现或提升竞争力。<sup>[16](https://www.sciencedirect.com/science/article/abs/pii/S0167739X16301674)</sup> 该领域的标准教科书参考是[艾伦·博罗丁](https://www.edgepedia.org/zh/allan-borodin)（Allan Borodin）与兰·埃尔-亚尼夫（Ran El-Yaniv）的《在线计算与竞争分析》（1998）。<sup>[17](https://www.charted.science/computer-science/theoretical-foundations/algorithms-and-complexity/online-algorithms)</sup>

## References

1. [Daniel Dominic Sleator, Robert Endre Tarjan (1985). Amortized Efficiency of List Update and Paging Rules. Commun. ACM 28(2): 202–208. dblp record](https://dblp.org/rec/journals/cacm/SleatorT85.html)
2. [D. D. Sleator and R. E. Tarjan. Amortized Efficiency of List Update and Paging Rules (full text PDF), Carnegie Mellon University](https://www.cs.cmu.edu/~sleator/papers/amortized-efficiency.pdf)
3. [Joan Boyar, Lene M. Favrholdt, Christian Kudahl, Kim S. Larsen, Jesper W. Mikkelsen. Online Algorithms with Advice: A Survey](https://www.cs.toronto.edu/~bor/2421f19/papers/boyar-survey.pdf)
4. [Andrew Templeton. Online Algorithms tech tree](https://templeton.host/tech-tree/online-algorithms/)
5. [Fabian Kuhn. Online Algorithms, Chapter 9, Algorithm Theory WS 2016/17, University of Freiburg](https://ac.informatik.uni-freiburg.de/teaching/ws16_17/algo1617/pdf/09_Online_p2.pdf)
6. [The k-server problem, ScienceDirect](https://www.sciencedirect.com/science/article/abs/pii/S1574013709000197)
7. [Boyar, Larsen, Maiti. A Comparison of Performance Measures via Online Search, arXiv:1106.6136](https://arxiv.org/abs/1106.6136)
8. [Competitive Analysis lecture notes, Technical University of Munich](https://mediatum.ub.tum.de/doc/1580033/document.pdf)
9. [Online Algorithms with Advice: A Survey, ACM version PDF, University of Southern Denmark](https://imada.sdu.dk/u/lenemf/Research/adviceSurvey.pdf)
10. [Daniel Sleator. Amortized Efficiency Of List Update and Paging Rules (abstract page), Carnegie Mellon University](https://www.cs.cmu.edu/~sleator/papers/Amortized-Efficiency.htm)
11. [Lecture 24: Online Algorithms, CMU](https://cmualgos.github.io/2018/10/24/online.html)
12. [Resource Augmentation for Online Algorithms, Lacuna](https://lacuna.tiptreesystems.com/direction/reconstructing-high-fidelity-images-with-learned-structural-priors/txn_85688c100ed649e6bfb691acb2a450c6)
13. [Boyar, Irani, Larsen. A Comparison of Performance Measures for Online Algorithms, arXiv:0806.0983](https://arxiv.org/abs/0806.0983)
14. [Competitive Analysis, Professional Level, Senior Stack roadmap](https://senior-stack.uz/Roadmap/Data/datastructures-and-algorithms/25-online-algorithms/01-competitive-analysis/professional/)
15. [Kumar, Purohit, Svitkina. Improving Online Algorithms via ML Predictions, arXiv:2407.17712](https://arxiv.org/abs/2407.17712)
16. [Competitive analysis of fundamental scheduling algorithms on a fault-prone machine and the impact of resource augmentation, Future Generation Computer Systems](https://www.sciencedirect.com/science/article/abs/pii/S0167739X16301674)
17. [Online Algorithms, Charted Science topic page](https://www.charted.science/computer-science/theoretical-foundations/algorithms-and-complexity/online-algorithms)
18. [The Randomized $k$-Server Conjecture is False!](https://arxiv.org/abs/2211.05753)

---
*Initially written Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › 算法与计算方法 › 算法概述

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/competitive-analysis-online-algorithms

English original: https://www.edgepedia.org/competitive-analysis-online-algorithms
