# 递归最大优先算法

递归最大优先（recursive largest first，RLF）算法是一种用于顶点着色的贪心启发式算法。顶点着色问题是指为图的顶点分配颜色，使得相邻顶点获得不同的颜色。该算法由弗兰克·莱顿（Frank Leighton）于1979年为大型调度问题提出，它与普通贪心着色的不同之处在于，它一次构造一个颜色类，将每个类提取为一个独立集，即一个其中任意两个顶点均不相邻的顶点集合。<sup>[1](https://nvlpubs.nist.gov/nistpubs/jres/84/jresv84n6p489_a1b.pdf)</sup><sup> • </sup><sup>[2](https://citeseerx.ist.psu.edu/document?doi=490bf7bb0c0d688a174bee2328b440df5638b3fa&repid=rep1&type=pdf)</sup>

| 关键事实 | 详情 |
|---|---|
| 起源 | 由弗兰克·莱顿于1979年发表，题为《一种用于大型调度问题的图着色算法》，《美国国家标准局研究杂志》84(6)：489<sup>[1](https://nvlpubs.nist.gov/nistpubs/jres/84/jresv84n6p489_a1b.pdf)</sup> |
| 策略 | 一次构造一个颜色类作为独立集，而非逐个为顶点着色<sup>[2](https://citeseerx.ist.psu.edu/document?doi=490bf7bb0c0d688a174bee2328b440df5638b3fa&repid=rep1&type=pdf)</sup> |
| 种子规则 | 每个新颜色类以剩余图中度数最大的未着色顶点作为起始<sup>[3](https://vectree.io/c/recursive-largest-first-algorithm)</sup> |
| 最坏情况代价 | 为n个节点的图着色需要O(n³)时间和O(n²)空间<sup>[1](https://nvlpubs.nist.gov/nistpubs/jres/84/jresv84n6p489_a1b.pdf)</sup> |
| 结构恒等式 | 对于n个顶点的图G，G的色数加上由G的补图导出之图的独立数等于n<sup>[4](https://www.tandfonline.com/doi/abs/10.1080/00207160701419114)</sup> |
| 地位 | 与贪心（首次适应）和DSATUR并列为经典的图着色构造启发式算法之一<sup>[3](https://vectree.io/c/recursive-largest-first-algorithm)</sup><sup> • </sup><sup>[5](https://www.jstage.jst.go.jp/article/transfun/advpub/0/advpub_2021DMP0011/_article/-char/en)</sup> |

## 算法的工作原理

RLF在构造当前颜色类的过程中维护两个未着色顶点集合：U₁，即不与任何已赋予当前颜色的顶点相邻的未着色顶点；以及U₂，即与至少一个此类顶点相邻的未着色顶点。颜色类在U₁中不断扩展直至极大，然后开始一个新的颜色类。<sup>[6](https://pmc.ncbi.nlm.nih.gov/articles/PMC6756213/)</sup>

一个颜色类的构造过程如下。以剩余图中度数最大的未着色顶点作为该类的种子，将该顶点放入当前类，并将其未着色邻居移入U₂。一旦有i个顶点被赋予当前颜色，算法便从U₁中选择（如果可能的话）一个顶点v_{i+1}，使得该顶点相对于U₂的度数在U₁的所有顶点中最大；若出现并列，则尽可能选择在U₁中度数最小的那个。<sup>[6](https://pmc.ncbi.nlm.nih.gov/articles/PMC6756213/)</sup> 每一次这样的选择都将该顶点锁定到类中，并将其未着色邻居从U₁推入U₂。当U₁为空时，该类完成，U₂中的每个顶点重新变为可选，过程在剩余的未着色子图上以新的颜色递归进行。<sup>[6](https://pmc.ncbi.nlm.nih.gov/articles/PMC6756213/)</sup><sup> • </sup><sup>[3](https://vectree.io/c/recursive-largest-first-algorithm)</sup>

两条选择规则决定了结果的质量。选择剩余顶点中度数最大者作为种子，可以将最难的顶点集中在早期处理；而从U₁中选择在U₂中邻居数最多的顶点，则使每次移除一个颜色类后的剩余图尽可能稀疏。<sup>[6](https://pmc.ncbi.nlm.nih.gov/articles/PMC6756213/)</sup> 这两条规则都要求在颜色类增长过程中重新计算未着色顶点诱导子图中的度数，这正是算法耗时之所在。<sup>[5](https://www.jstage.jst.go.jp/article/transfun/advpub/0/advpub_2021DMP0011/_article/-char/en)</sup>

## 复杂度与结构

莱顿1979年的论文分析了四种着色算法，包括RLF，并证明这四种算法为n个节点的图着色均需要O(n³)时间和O(n²)空间。论文指出，尽管这种最坏情况行为在实践中不可接受，但与之一起讨论的近似最大独立集（AMIS）算法是该组中唯一已知其最坏情况表现并非最差的算法。<sup>[1](https://nvlpubs.nist.gov/nistpubs/jres/84/jresv84n6p489_a1b.pdf)</sup> 后来的综述文献将RLF的最坏情况时间复杂度表述为O(|V|³)。<sup>[7](https://www.mathematik.tu-clausthal.de/fileadmin/Mathematik/AG-GraphentheorieKombinatorik/papers/gca.pdf)</sup>

2008年发表在《国际计算机数学杂志》上的一篇论文通过一个归约将RLF式着色与最大独立集问题（MISP）联系起来，证明给定一个n个顶点的图G，将G的色数加上由G的补图构造之图的独立数，恰好等于n。这一恒等式形式化了RLF设计背后的直觉：提取大独立集与着色是从另一侧看待的同一结构性任务。<sup>[4](https://www.tandfonline.com/doi/abs/10.1080/00207160701419114)</sup> 算法选择方面的文献同样将RLF描述为一种基于大独立集提取的贪心方法。<sup>[2](https://citeseerx.ist.psu.edu/document?doi=490bf7bb0c0d688a174bee2328b440df5638b3fa&repid=rep1&type=pdf)</sup>

## 与其他启发式算法的比较

RLF经常与另外两种经典构造启发式算法进行基准比较：普通贪心着色，即按固定顺序取顶点并赋予其最低可用颜色；以及DSATUR（饱和度），即优先为邻居所用颜色种类最多的未着色顶点着色。<sup>[5](https://www.jstage.jst.go.jp/article/transfun/advpub/0/advpub_2021DMP0011/_article/-char/en)</sup><sup> • </sup><sup>[8](https://www.sciencedirect.com/science/article/pii/S0305054811002966)</sup>

在质量方面，许多实例上的通常排序将RLF排在DSATUR之前，而DSATUR通常又优于普通贪心，代价是更多的计算量。一项关于光网络规划的研究——其中用着色为波长到通信路径的分配建模——报告了若干网络实例上的平均颜色数：<sup>[9](https://repositorio.iscte-iul.pt/bitstream/10071/22030/4/master_ines_leandro_duarte.pdf)</sup>

| 网络 | 贪心 | DSATUR | RLF |
|---|---|---|---|
| COST 239 | 4.0 | 4.2 | 4.5 |
| NSFNET | 4.1 | 4.7 | 5.7 |
| UBN | 7.2 | 8.4 | 9.2 |
| CONUS 30 | 14.2 | 16.5 | 17.5 |
| CONUS 60 | 162.4 | 164.4 | 167.5 |
| GT-ITM 27 | 8.9 | 10.7 | 11.2 |
| GT-ITM 34 | 16.7 | 17.4 | 18.1 |

在该应用中，排序恰好相反：贪心使用的波长最少，RLF最多；研究还指出，基于着色的方法计算时间略高于较简单的替代方法。这一结果表明，RLF的独立集构造并非在每个实例类上都占优。<sup>[9](https://repositorio.iscte-iul.pt/bitstream/10071/22030/4/master_ines_leandro_duarte.pdf)</sup>

## 应用与后续改进

图着色启发式算法适用于任何需要将冲突划分为相容组的场景。RLF出现在寄存器分配研究的经典基线方法之中——在寄存器分配中，在硬件寄存器上冲突的变量构成一个待着色的冲突图；一种用于寄存器分配的深度学习混合分配器将其结果与著名的贪心算法DSATUR和RLF进行了比较。<sup>[10](https://arxiv.org/abs/1912.03700)</sup> 高层次综合中的寄存器堆分配同样被建模为对冲突图进行着色，该冲突图由已调度数据流图的读/写分析导出。<sup>[11](https://www.sciencedirect.com/science/article/pii/S0141933198000477)</sup>

RLF和DSATUR的主要实际弱点是需要在未着色子图中反复重新计算度数：输入图的边密度越高，处理时间越长。2022年，冈山理科大学和电气通信大学的金原一穗（Kazuho Kanahara）、片山宪吾（Kengo Katayama）和富田悦次（Etsuji Tomita）提出了一种自适应度数更新（Adaptive Degree Updating，ADU）方法，用于两种算法的度数维护，并在DIMACS基准图和大小、密度各异的随机图上证明，改进后的构造算法比传统算法运行更快，在边密度较高的大图上加速最为显著。<sup>[5](https://www.jstage.jst.go.jp/article/transfun/advpub/0/advpub_2021DMP0011/_article/-char/en)</sup>

## References

1. [F. T. Leighton (1979). A graph coloring algorithm for large scheduling problems. Journal of Research of the National Bureau of Standards 84(6): 489.](https://nvlpubs.nist.gov/nistpubs/jres/84/jresv84n6p489_a1b.pdf)
2. [Algorithm Selection for the Graph Coloring Problem (CiteSeerX copy).](https://citeseerx.ist.psu.edu/document?doi=490bf7bb0c0d688a174bee2328b440df5638b3fa&repid=rep1&type=pdf)
3. [Recursive largest first algorithm, Visual Explainer, Vectree.](https://vectree.io/c/recursive-largest-first-algorithm)
4. [On the recursive largest first algorithm for graph colouring, International Journal of Computer Mathematics 85(2).](https://www.tandfonline.com/doi/abs/10.1080/00207160701419114)
5. [K. Kanahara, K. Katayama, E. Tomita (2022). Speeding-up Construction Algorithms for the Graph Coloring Problem. IEICE Transactions on Fundamentals, Vol. E105.A, No. 9, pp. 1241–1251.](https://www.jstage.jst.go.jp/article/transfun/advpub/0/advpub_2021DMP0011/_article/-char/en)
6. [A Graph Coloring Algorithm for Large Scheduling Problems (PMC copy of the Leighton paper).](https://pmc.ncbi.nlm.nih.gov/articles/PMC6756213/)
7. [Graph Coloring Algorithms (survey), TU Clausthal.](https://www.mathematik.tu-clausthal.de/fileadmin/Mathematik/AG-GraphentheorieKombinatorik/papers/gca.pdf)
8. [A new DSATUR-based algorithm for exact vertex coloring, Computers & Operations Research.](https://www.sciencedirect.com/science/article/pii/S0305054811002966)
9. [Inês Leandro Duarte. Exploring Graph Coloring Heuristics for Optical Networks Planning, Master's thesis, ISCTE-IUL.](https://repositorio.iscte-iul.pt/bitstream/10071/22030/4/master_ines_leandro_duarte.pdf)
10. [Deep Learning-based Hybrid Graph-Coloring Algorithm for Register Allocation, arXiv:1912.03700.](https://arxiv.org/abs/1912.03700)
11. [Register-file allocation via graph coloring, ScienceDirect.](https://www.sciencedirect.com/science/article/pii/S0141933198000477)

---
*Initially written Sep 17, 2026 · Reviewed: 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 › Graph coloring algorithms

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/recursive-largest-first-algorithm

English original: https://www.edgepedia.org/recursive-largest-first-algorithm
