# 图着色

**图着色**（Graph coloring）是指为图的顶点分配标号——传统上称为颜色——使得任意两个相邻的顶点不获得相同的颜色；**色数**χ(G) 是足够使用的最少颜色数。<sup>[1](https://math.libretexts.org/Bookshelves/Combinatorics_and_Discrete_Mathematics/Combinatorics_and_Graph_Theory_%28Guichard%29/05%3A_Graph_Theory/5.08%3A_Graph_Coloring)</sup> 该问题起源于地图着色，即相邻国家必须被赋予不同的颜色，后来成为图论和理论计算机科学的核心问题。<sup>[2](https://www.cs.cornell.edu/courses/cs3110/2012sp/recitations/rec21-graphs/rec21.html)</sup>

| 关键事实 | 详情 |
|---|---|
| 定义 | 正常着色为顶点分配颜色使相邻顶点颜色不同；χ(G) 是所需的最少颜色数<sup>[1](https://math.libretexts.org/Bookshelves/Combinatorics_and_Discrete_Mathematics/Combinatorics_and_Graph_Theory_%28Guichard%29/05%3A_Graph_Theory/5.08%3A_Graph_Coloring)</sup> |
| 基本界 | 对于 n 个顶点的图，1 ≤ χ(G) ≤ n；χ(G) 至少为团数，至多为 Δ(G) + 1，其中 Δ 为最大度<sup>[1](https://math.libretexts.org/Bookshelves/Combinatorics_and_Discrete_Mathematics/Combinatorics_and_Graph_Theory_%28Guichard%29/05%3A_Graph_Theory/5.08%3A_Graph_Coloring)</sup> |
| 布鲁克斯定理（1941） | 每个图满足 χ(G) ≤ Δ(G)，除非它是完全图或奇环，此时 χ(G) = Δ(G) + 1<sup>[3](https://discrete.openmathbooks.org/preview/sec_coloring.html)</sup> |
| 复杂性 | 判定 χ(G) ≤ k 对于 k ≥ 3 是 NP 完全的，即使 k = 3 时也是如此（加雷、约翰逊和斯托克迈耶，1976）<sup>[4](https://mathworld.wolfram.com/VertexColoringProblem.html)</sup> |
| 二部图情形 | 一个图是二部图当且仅当它是 2-可着色的，可通过广度优先搜索在 O(\|V\| + \|E\|) 时间内检测<sup>[1](https://math.libretexts.org/Bookshelves/Combinatorics_and_Discrete_Mathematics/Combinatorics_and_Graph_Theory_%28Guichard%29/05%3A_Graph_Theory/5.08%3A_Graph_Coloring)</sup><sup> • </sup><sup>[2](https://www.cs.cornell.edu/courses/cs3110/2012sp/recitations/rec21-graphs/rec21.html)</sup> |
| 平面图情形 | 每个平面图都是 4-可着色的；四色定理由肯尼思·阿佩尔和沃尔夫冈·哈肯于 1976 年借助计算机证明<sup>[5](https://blogs.ams.org/mathgradblog/2014/06/29/color-theorem/)</sup> |
| 应用 | 编译器中的寄存器分配、课程表与考试安排、无线电台频率分配、交通信号相位设计<sup>[6](https://www.cs.cornell.edu/courses/cs4120/2026sp/notes.html?id=regalloc)</sup><sup> • </sup><sup>[7](https://doi.org/10.1093%2Fcomjnl%2F10.1.85)</sup><sup> • </sup><sup>[1](https://math.libretexts.org/Bookshelves/Combinatorics_and_Discrete_Mathematics/Combinatorics_and_Graph_Theory_%28Guichard%29/05%3A_Graph_Theory/5.08%3A_Graph_Coloring)</sup> |

## 定义与基本结构

图的**正常着色**是为顶点分配颜色使得任意两个相邻顶点不具有相同颜色；颜色可以是任意互不相同的标号，例如整数。色数 χ(G) 是所需的最少颜色数。可以用 k 种或更少颜色着色的图称为 k-可着色的。<sup>[1](https://math.libretexts.org/Bookshelves/Combinatorics_and_Discrete_Mathematics/Combinatorics_and_Graph_Theory_%28Guichard%29/05%3A_Graph_Theory/5.08%3A_Graph_Coloring)</sup>

着色与**独立集**——即两两不相邻的顶点集合——密切相关。在任何正常着色中，同一种颜色的顶点构成一个独立集，称为一个色类。对于 n 个顶点、独立数为 α 的图，各色类的大小给出界 n/α ≤ χ，因为每个色类至多包含 α 个顶点。<sup>[1](https://math.libretexts.org/Bookshelves/Combinatorics_and_Discrete_Mathematics/Combinatorics_and_Graph_Theory_%28Guichard%29/05%3A_Graph_Theory/5.08%3A_Graph_Coloring)</sup>

**团**是两两相邻的顶点集合，构成完全图 K<sub>n</sub> 的一个副本。大小为 n 的团不能用少于 n 种颜色着色，因此 G 的团数是 χ(G) 的一个下界。<sup>[3](https://discrete.openmathbooks.org/preview/sec_coloring.html)</sup> 该界一般并不紧：存在色数高而团数低的图。1959 年，[保罗·埃尔德什](https://www.edgepedia.org/zh/paul-erdos)（Paul Erdős）证明了围长与色数均可任意大的图的存在性——围长即图中最小环的大小——这是一个强得多的结果。<sup>[1](https://math.libretexts.org/Bookshelves/Combinatorics_and_Discrete_Mathematics/Combinatorics_and_Graph_Theory_%28Guichard%29/05%3A_Graph_Theory/5.08%3A_Graph_Coloring)</sup>

一个图是**二部图**恰好当它是 2-可着色的，因为此时两个色类构成二部划分。这可以通过对广度优先搜索的各层交替着色并检查每条边连接不同颜色来检测，时间复杂度为 O(|V| + |E|)。<sup>[2](https://www.cs.cornell.edu/courses/cs3110/2012sp/recitations/rec21-graphs/rec21.html)</sup>

## 上界与布鲁克斯定理

一个简单的贪心过程——依次为每个顶点着以其已着色邻居未使用的最小颜色——总是能用 Δ(G) + 1 种颜色成功，因为一个顶点至多有 Δ(G) 个邻居。更细致地，按距选定最后顶点的距离递减排序顶点，可以证明任何非正则图满足 χ ≤ Δ。<sup>[1](https://math.libretexts.org/Bookshelves/Combinatorics_and_Discrete_Mathematics/Combinatorics_and_Graph_Theory_%28Guichard%29/05%3A_Graph_Theory/5.08%3A_Graph_Coloring)</sup>

**布鲁克斯定理**将此改进为最佳可能的一般界。任何图 G 满足 χ(G) ≤ Δ(G)，除非 G 是完全图或奇环，此时 χ(G) = Δ(G) + 1。完全图 K<sub>n</sub> 的 χ = n 但 Δ = n − 1，奇环的 χ = 3 但 Δ = 2；这是达到朴素界的仅有的两类图。<sup>[3](https://discrete.openmathbooks.org/preview/sec_coloring.html)</sup> R. L. 布鲁克斯 1941 年的论文包含了关于抽象图着色的第一个结果，一般图的顶点着色由此成为研究对象；A. B. 肯普早在 1879 年关于地图着色的工作中就指出，色数值得在平面图之外进行研究。<sup>[8](https://resolve.cambridge.org/core/services/aop-cambridge-core/content/view/854C6C31329CA1F88FA91417A1F645BC/9781139519793c2_p36-55_CBO.pdf/brookss-theorem.pdf)</sup> 此后，布鲁克斯定理引发了大量关于列表着色、图的幂及其他变体的推广文献。<sup>[8](https://resolve.cambridge.org/core/services/aop-cambridge-core/content/view/854C6C31329CA1F88FA91417A1F645BC/9781139519793c2_p36-55_CBO.pdf/brookss-theorem.pdf)</sup>

贪心算法本身只是一种启发式方法：色数为 3 的图在不利的顶点排序下可能被迫使用 4 种颜色。<sup>[1](https://math.libretexts.org/Bookshelves/Combinatorics_and_Discrete_Mathematics/Combinatorics_and_Graph_Theory_%28Guichard%29/05%3A_Graph_Theory/5.08%3A_Graph_Coloring)</sup> 韦尔什和鲍威尔在 1967 年的论文中给出了一个易于计算的、以顶点度表示的色数上界及相应的着色算法，该论文还将该问题与排课联系起来。<sup>[7](https://doi.org/10.1093%2Fcomjnl%2F10.1.85)</sup>

## 计算复杂性

判定 χ(G) ≤ k 对于 k ≥ 3 是 NP 完全的；k = 3 的情形由加雷、约翰逊和斯托克迈耶于 1976 年证明为 NP 完全，这使得寻找最小着色的优化问题是 NP 困难的。<sup>[4](https://mathworld.wolfram.com/VertexColoringProblem.html)</sup> 目前不知道计算一般图色数的有效算法。<sup>[3](https://discrete.openmathbooks.org/preview/sec_coloring.html)</sup> 精确解可通过穷举搜索获得，而布雷拉兹算法等启发式方法能找到较好但不一定是最小的着色；梅赫罗特拉和特里克 1996 年的列生成方法能快速求解大多数中小规模实例。<sup>[4](https://mathworld.wolfram.com/VertexColoringProblem.html)</sup>

**色多项式** π<sub>G</sub>(z) 计算 G 对每个整数 k 的不同 k-着色数，而 χ(G) 是使 π<sub>G</sub>(z) > 0 的最小正整数 z。<sup>[9](https://mathworld.wolfram.com/ChromaticPolynomial.html)</sup>

## 四色定理

最著名的着色问题是：是否每个平面图——即可在平面上无交叉地画出的图——都是 4-可着色的。[四色定理](https://www.edgepedia.org/zh/four-color-theorem)由肯尼思·阿佩尔和沃尔夫冈·哈肯于 1976 年证明，约翰·A. 科赫提供了算法辅助，这是第一个借助大量计算机帮助证明的重大定理。<sup>[5](https://blogs.ams.org/mathgradblog/2014/06/29/color-theorem/)</sup> 他们的反证法将问题归结为检查 1,936 张地图的集合，每张都被证明不会出现在最小反例中；计算机检查耗时超过一千小时，而不可免部分需要数百页的手工验证。<sup>[5](https://blogs.ams.org/mathgradblog/2014/06/29/color-theorem/)</sup> 罗伯逊、桑德斯、西摩和托马斯于 1996 年宣布了一个更简单的计算机辅助证明。<sup>[10](https://www.ams.org/era/1996-02-01/S1079-6762-96-00003-0/S1079-6762-96-00003-0.pdf)</sup> 该定理仅适用于平面图：无线电台的频率分配图可以具有色数 5 而不与之矛盾，因为该图不是平面图。<sup>[3](https://discrete.openmathbooks.org/preview/sec_coloring.html)</sup>

## 完美图

若一个图的每个诱导子图的色数都等于其团数，则称该图为**完美图**。对于[完美图](https://www.edgepedia.org/zh/perfect-graph)，求色数归结为寻找最大团；[弦图](https://www.edgepedia.org/zh/chordal-graph)——其中每个长度至少为四的环都含有一条弦——是被证明为完美的一类图。<sup>[3](https://discrete.openmathbooks.org/preview/sec_coloring.html)</sup><sup> • </sup><sup>[14](https://mathworld.wolfram.com/ChordalGraph.html)</sup> 团数等于色数、但不要求满足诱导子图条件的图称为弱完美图。<sup>[11](https://mathworld.wolfram.com/ChromaticNumber.html)</sup>

## 边着色

边可以类似地着色，要求与同一顶点关联的边获得不同颜色；最少颜色数称为**色指数** χ′(G)。<sup>[3](https://discrete.openmathbooks.org/preview/sec_coloring.html)</sup> 维京的一个定理由古普塔独立证明，指出任何简单图的边色数要么是 Δ(G)，要么是 Δ(G) + 1。<sup>[12](https://link.springer.com/chapter/10.1007/978-981-96-4745-3_1)</sup> 根据定义，G 的边色数等于其线图的色数。<sup>[11](https://mathworld.wolfram.com/ChromaticNumber.html)</sup>

## 应用

**寄存器分配。** 在编译器中，同时活跃的两个变量不能占用同一个硬件寄存器。编译器构建一个干涉图，其顶点为变量，边连接相互干涉的变量对；用 k 种颜色对该图着色恰好就是代码能否用 k 个寄存器进行寄存器分配的问题。[格雷戈里·柴廷](https://www.edgepedia.org/zh/gregory-chaitin)及其同事在 20 世纪 80 年代初首次表明，图着色可以构成有效寄存器分配算法的基础。<sup>[6](https://www.cs.cornell.edu/courses/cs4120/2026sp/notes.html?id=regalloc)</sup> 尽管该问题是 NP 完全的，但在这种场景下是实用的，因为分配器可以将变量溢出到内存而不必精确判定问题，且简单的启发式方法即可达到接近最优的着色。肯普 1879 年为尝试证明四色定理而发展的启发式方法，于 1979 年被柴廷改编用于寄存器分配；由此得到的肯普-柴廷算法首先移除低度节点，保证它们有可用颜色。<sup>[13](https://www.cs.cornell.edu/courses/cs4160/2019sp/terse/vfa/Color.html)</sup>

**调度与排课。** 顶点可以表示课程、考试或任务，边连接因共享学生、工人或资源而冲突的对；k-着色则分配 k 个时间段且无冲突，色数即为所需的最少时间段数。<sup>[2](https://www.cs.cornell.edu/courses/cs3110/2012sp/recitations/rec21-graphs/rec21.html)</sup> 韦尔什和鲍威尔 1967 年的论文明确建立了这一联系用于排课。<sup>[7](https://doi.org/10.1093%2Fcomjnl%2F10.1.85)</sup> 同样的模型用于为无线电台分配互不干扰的频率，以及指定可同时亮绿灯的交通信号组。<sup>[1](https://math.libretexts.org/Bookshelves/Combinatorics_and_Discrete_Mathematics/Combinatorics_and_Graph_Theory_%28Guichard%29/05%3A_Graph_Theory/5.08%3A_Graph_Coloring)</sup>

## References

1. [Graph Coloring, Guichard, Mathematics LibreTexts](https://math.libretexts.org/Bookshelves/Combinatorics_and_Discrete_Mathematics/Combinatorics_and_Graph_Theory_%28Guichard%29/05%3A_Graph_Theory/5.08%3A_Graph_Coloring)
2. [Graph algorithms, CS 3110 recitation, Cornell University](https://www.cs.cornell.edu/courses/cs3110/2012sp/recitations/rec21-graphs/rec21.html)
3. [Coloring, Discrete Mathematics, OpenMathBooks](https://discrete.openmathbooks.org/preview/sec_coloring.html)
4. [Vertex Coloring Problem, Wolfram MathWorld](https://mathworld.wolfram.com/VertexColoringProblem.html)
5. [The Four Color Theorem, AMS Math Grad Blog](https://blogs.ams.org/mathgradblog/2014/06/29/color-theorem/)
6. [Register allocation notes, CS 4120, Cornell University](https://www.cs.cornell.edu/courses/cs4120/2026sp/notes.html?id=regalloc)
7. [D. J. A. Welsh and M. B. Powell (1967). An upper bound for the chromatic number of a graph and its application to timetabling problems. The Computer Journal 10(1), 85–86.](https://doi.org/10.1093%2Fcomjnl%2F10.1.85)
8. [M. Stiebitz and B. Toft. Brooks's theorem, in Topics in Chromatic Graph Theory, Cambridge University Press](https://resolve.cambridge.org/core/services/aop-cambridge-core/content/view/854C6C31329CA1F88FA91417A1F645BC/9781139519793c2_p36-55_CBO.pdf/brookss-theorem.pdf)
9. [Chromatic Polynomial, Wolfram MathWorld](https://mathworld.wolfram.com/ChromaticPolynomial.html)
10. [N. Robertson, D. Sanders, P. Seymour, R. Thomas (1996). A New Proof of the Four-Colour Theorem. Electronic Research Announcements of the AMS](https://www.ams.org/era/1996-02-01/S1079-6762-96-00003-0/S1079-6762-96-00003-0.pdf)
11. [Chromatic Number, Wolfram MathWorld](https://mathworld.wolfram.com/ChromaticNumber.html)
12. [Graph Theory Fundamentals, Springer Nature Link](https://link.springer.com/chapter/10.1007/978-981-96-4745-3_1)
13. [Color: Graph Coloring, Verified Functional Algorithms, Cornell University](https://www.cs.cornell.edu/courses/cs4160/2019sp/terse/vfa/Color.html)
14. [Chordal Graph -- from Wolfram MathWorld](https://mathworld.wolfram.com/ChordalGraph.html)

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

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › Algorithms and computational methods › Graph and network algorithms › Graph coloring and independent sets

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/graph-coloring

English original: https://www.edgepedia.org/graph-coloring
