# 凯莱公式

**凯莱公式**是图论中的一个结果，它指出：\( n \) 个顶点上的标号树的数量为 \( n^{n-2} \)。标号树是指顶点带有不同标号的树，标号通常取 \( [n] = \{1, 2, \dots, n\} \)；由于 \( n \) 个顶点上的每一棵标号树都是完全图 \( K_n \) 的一棵生成树，该公式等价于说 \( \tau(K_n) = n^{n-2} \)，其中 \( \tau(G) \) 表示 \( G \) 的生成树数目。<sup>[1](https://appliedcombinatorics.org/book/s_graphs_counting-trees.html)</sup><sup> • </sup><sup>[2](https://github.com/justinbrianhwang/SJ-wiki/blob/main/docs/math/graph-theory/counting-trees-and-prufer-sequences.md)</sup>

| 关键事实 | 详情 |
|---|---|
| 陈述 | \( n \) 个顶点上的标号树数目 \( T_n \) 为 \( n^{n-2} \)<sup>[1](https://appliedcombinatorics.org/book/s_graphs_counting-trees.html)</sup> |
| 最初几项 | 当 \( n = 1, 2, 3, 4, 5, 6 \) 时依次为 1, 1, 3, 16, 125, 1296, …（OEIS A000272）<sup>[3](https://mathworld.wolfram.com/LabeledTree.html)</sup> |
| 归属 | 凯莱于 1889 年用图论术语陈述并证明了它；等价的结果此前已由西尔维斯特（1857）和博尔夏特（1860）证明<sup>[1](https://appliedcombinatorics.org/book/s_graphs_counting-trees.html)</sup> |
| 标准证明 | 普吕弗 1918 年给出的标号树与 \( [n] \) 上长度为 \( n-2 \) 的序列之间的双射<sup>[1](https://appliedcombinatorics.org/book/s_graphs_counting-trees.html)</sup> |
| 度数公式 | 若标号 \( i \) 在普吕弗编码中出现 \( a_i \) 次，则 \( \deg(i) = a_i + 1 \)<sup>[2](https://github.com/justinbrianhwang/SJ-wiki/blob/main/docs/math/graph-theory/counting-trees-and-prufer-sequences.md)</sup> |
| 度序列 | 度序列为 \( (d_1, \dots, d_n) \) 的标号树数目为 \( \frac{(n-2)!}{(d_1-1)!(d_2-1)!\cdots(d_n-1)!} \)<sup>[2](https://github.com/justinbrianhwang/SJ-wiki/blob/main/docs/math/graph-theory/counting-trees-and-prufer-sequences.md)</sup> |
| 适用范围 | 这是一个关于标号树的结果；它不计数无标号树的形状、有根树，或在缺少额外对称性分析时的化学异构体<sup>[2](https://github.com/justinbrianhwang/SJ-wiki/blob/main/docs/math/graph-theory/counting-trees-and-prufer-sequences.md)</sup> |

## 陈述与简单情形

该公式计数的是顶点集固定的树。当 \( n = 1 \) 和 \( n = 2 \) 时，各只有一棵树。当 \( n = 3 \) 时，所有树都同构于路径 \( P_3 \)，三种标号方式对应于选择哪个顶点为度 2 的顶点，因此 \( T_3 = 3 \)。当 \( n = 4 \) 时有两种形状：星形 \( K_{1,3} \) 有 4 种标号方式，路径 \( P_4 \) 有 12 种标号方式，合计 \( T_4 = 16 \)。当 \( n = 5 \) 时，三种形状分别给出 \( 5 + 60 + 60 = 125 = 5^3 \) 种标号方式。<sup>[1](https://appliedcombinatorics.org/book/s_graphs_counting-trees.html)</sup>该序列继续为 1, 1, 3, 16, 125, 1296, …<sup>[3](https://mathworld.wolfram.com/LabeledTree.html)</sup>

## 普吕弗编码证明

最广为使用的证明由海因茨·普吕弗给出，发表于 1918 年，它在 \( n \) 个顶点上的标号树与长度为 \( n-2 \)、符号取自 \( [n] \) 的字符串之间建立了一个双射。<sup>[1](https://appliedcombinatorics.org/book/s_graphs_counting-trees.html)</sup>编码通过反复删除叶子来进行：找到标号最小的叶子，记录其唯一邻接顶点的标号，然后删去该叶子；重复此过程直到只剩两个顶点，最后返回所记录的序列。<sup>[1](https://appliedcombinatorics.org/book/s_graphs_counting-trees.html)</sup><sup> • </sup><sup>[4](https://github.com/cp-algorithms/cp-algorithms/blob/main/src/graph/pruefer_code.md)</sup>一棵 \( n \ge 2 \) 个顶点的树产生一个含 \( n-2 \) 个整数的序列，且该过程是可逆的：编码中未出现的标号恰好是叶子，最小的缺失标号与编码的第一个符号相连，通过归纳可唯一地重建这棵树。<sup>[1](https://appliedcombinatorics.org/book/s_graphs_counting-trees.html)</sup>

由于 \( n-2 \) 个位置中的每一个都可以填入 \( n \) 个标号中的任意一个，因此共有 \( n^{n-2} \) 个可能的编码，双射将这个计数转移到了树上。<sup>[1](https://appliedcombinatorics.org/book/s_graphs_counting-trees.html)</sup><sup> • </sup><sup>[4](https://github.com/cp-algorithms/cp-algorithms/blob/main/src/graph/pruefer_code.md)</sup>同一个双射还使度数结构变得可见：在一个顶点变为叶子或留到最后两个顶点之前，每删去一个与它相邻的叶子，该顶点就被记录一次，因此出现 \( a_i \) 次的标号属于一个度为 \( a_i + 1 \) 的顶点，而从未出现的标号属于一个叶子。<sup>[2](https://github.com/justinbrianhwang/SJ-wiki/blob/main/docs/math/graph-theory/counting-trees-and-prufer-sequences.md)</sup>

## 对度序列的推论

度数公式将关于树结构的问题转化为关于符号在字符串中出现频率的问题。正整数序列 \( (d_1, \dots, d_n) \) 是某棵标号树的度序列，只有当 \( d_1 + \cdots + d_n = 2(n-1) \)；当此条件成立时，标号 \( i \) 必须在编码中出现 \( d_i - 1 \) 次。因此，具有该确切度序列的标号树数目为多重组合计数 \( \frac{(n-2)!}{(d_1-1)!(d_2-1)!\cdots(d_n-1)!} \)，这往往是计数具有指定叶子或枢纽的树的最快捷方法。<sup>[2](https://github.com/justinbrianhwang/SJ-wiki/blob/main/docs/math/graph-theory/counting-trees-and-prufer-sequences.md)</sup>

该双射还给出了一种简单的抽样方法：要均匀随机地抽取一棵标号树，只需生成一个 \( [n] \) 上长度为 \( n-2 \) 的随机序列并将其解码。<sup>[5](https://learngraphtheory.org/articles/trees-in-graph-theory.html)</sup>对所有树取平均，一棵均匀随机的标号树的期望顶点度数为 \( \mathbb{E}[\deg(v)] = \frac{2(n-1)}{n} \)，当 \( n \to \infty \) 时趋于 2。<sup>[6](https://jackxtong.github.io/Blogs/Graph_theory/cayley_trees.html)</sup>

## 与矩阵树定理的关系

基尔霍夫的矩阵树定理将任意有限图的生成树数目表示为一个拉普拉斯余子式的行列式。将其应用于 \( K_n \) 可重现凯莱公式：对于 \( K_6 \)，该行列式的值为 1296，等于 \( 6^4 \)，且对每个完全图都成立。<sup>[7](https://simonrs.com/eulercircle/irpw2025/omar-spanning-paper.pdf)</sup>两种方法在 \( K_n \) 上一致，但回答的是不同种类的问题：普吕弗编码对完全图是显式且构造性的，而拉普拉斯余子式则能处理缺失边和加权变体。<sup>[2](https://github.com/justinbrianhwang/SJ-wiki/blob/main/docs/math/graph-theory/counting-trees-and-prufer-sequences.md)</sup>

除这两种之外，凯莱公式还有许多其他证明，包括通过拉格朗日反演、通过随机映射以及通过度序列的证明；艾格纳、齐格勒和霍夫曼所著《数学天书中的证明》一书中有关凯莱公式的章节介绍了四种不同的证明技巧。<sup>[1](https://appliedcombinatorics.org/book/s_graphs_counting-trees.html)</sup><sup> • </sup><sup>[8](https://cameroncounts.wordpress.com/wp-content/uploads/2013/12/ec.pdf)</sup><sup> • </sup><sup>[9](https://arxiv.org/abs/1409.1614)</sup>

## 历史

阿瑟·凯莱（1821–1895）于 1889 年在《数学季刊》第 23 卷第 376–378 页发表了题为《关于树的一个定理》的论文。等价的结果此前已由詹姆斯·J·西尔维斯特（1857）和卡尔·W·博尔夏特（1860）证明；公式之所以冠以凯莱之名，是因为他是第一个用图论术语陈述并证明它的人。有人可能会说，凯莱实际上只对 \( n = 6 \) 作了证明，并声称可推广到所有 \( n \)，而这种推广是否真的出现在他的工作中尚有争议。普吕弗 1918 年的证明是在大量图论术语已经确立之后出现的，然而他是在排列和他自己的术语体系的背景下工作的，显然并未意识到他的方法所包含的图论框架。<sup>[10](https://www.sciencedirect.com/science/article/pii/0012365X9190138R)</sup><sup> • </sup><sup>[3](https://mathworld.wolfram.com/LabeledTree.html)</sup><sup> • </sup><sup>[1](https://appliedcombinatorics.org/book/s_graphs_counting-trees.html)</sup><sup> • </sup><sup>[1](https://appliedcombinatorics.org/book/s_graphs_counting-trees.html)</sup>

## 推广与局限

普吕弗编码支持比凯莱公式本身更一般的计数公式。一个应用是计数向一个具有 \( n \) 个顶点、\( m \) 条边和 \( k \) 个连通分量的图添加 \( k-1 \) 条边使其连通的方式数，这也是所需的最少边数。<sup>[4](https://github.com/cp-algorithms/cp-algorithms/blob/main/src/graph/pruefer_code.md)</sup>编码的概念还被推广到了顶点染色的有根树，其中两棵标号树同构当且仅当它们的普吕弗编码完全相同。<sup>[11](https://arxiv.org/abs/2506.15796)</sup>

该公式的适用范围是标号、无根、无向的树。计数无标号树更为困难，因为对称性会将许多标号树归并为一个形状：\( n \) 个顶点上的所有星形共享同一个无标号形状，但对应于 \( n \) 个不同的标号星形，每个中心的选择对应一个。因此，在没有额外对称性分析的情况下，不应用凯莱公式来计算化学异构体数目或有根形状数目。<sup>[2](https://github.com/justinbrianhwang/SJ-wiki/blob/main/docs/math/graph-theory/counting-trees-and-prufer-sequences.md)</sup>它也不计数有根树、有向树或无标号树。<sup>[12](https://www.proofatlas.ai/formalizations/cayley-tree-formula/)</sup>

## References

1. [Section 5.6 Counting Labeled Trees, Applied Combinatorics (Trotter and Keller)](https://appliedcombinatorics.org/book/s_graphs_counting-trees.html)
2. [Counting Trees and Prüfer Sequences, SJ-wiki](https://github.com/justinbrianhwang/SJ-wiki/blob/main/docs/math/graph-theory/counting-trees-and-prufer-sequences.md)
3. [Labeled Tree, Wolfram MathWorld](https://mathworld.wolfram.com/LabeledTree.html)
4. [Prüfer code, cp-algorithms](https://github.com/cp-algorithms/cp-algorithms/blob/main/src/graph/pruefer_code.md)
5. [Trees in Graph Theory, Learn Graph Theory](https://learngraphtheory.org/articles/trees-in-graph-theory.html)
6. [Cayley Trees and k-Regular Trees, TX Blogs](https://jackxtong.github.io/Blogs/Graph_theory/cayley_trees.html)
7. [Matrix Tree Theorem and the Number of Spanning Trees (Omar Said, IRPW)](https://simonrs.com/eulercircle/irpw2025/omar-spanning-paper.pdf)
8. [Cayley's Theorem, lecture notes of Peter Cameron](https://cameroncounts.wordpress.com/wp-content/uploads/2013/12/ec.pdf)
9. [An Elementary Proof of the Cayley Formula Using Random Maps, arXiv](https://arxiv.org/abs/1409.1614)
10. [Tree codes that preserve increases and degree sequences, Discrete Mathematics (ScienceDirect)](https://www.sciencedirect.com/science/article/pii/0012365X9190138R)
11. [Prüfer codes on vertex-colored rooted trees, arXiv](https://arxiv.org/abs/2506.15796)
12. [Cayley's Formula for Labeled Trees, ProofAtlas](https://www.proofatlas.ai/formalizations/cayley-tree-formula/)

---
*Initially written Oct 15, 2026*

Topic: 物质世界与数学 › 数学与统计学 › 逻辑与离散数学 › General discrete mathematics and discrete structures › Graph theory › Graph theory subfields and named results › Named graph theory theorems

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/cayleys-formula

English original: https://www.edgepedia.org/cayleys-formula
