---
id: 1184
lang: en
translation_of: index.md
source_sha256: ac17ccd083c67580f0c75b919873126979ca9c20b27cc5c4fec5e69856e356ca
title: "Cayley's Theorem & the Extended Cayley Theorem"
description: "The number of labeled unrooted trees on n nodes is n^(n-2), proved with Prufer sequences, followed by the extended Cayley theorem."
tags: ["OI","Math","Graph Theory","Counting","Tree Theory","Cayley","Prufer"]
translated: 2026-11-27
translator: Claude Opus 5.5
translator_model: claude-opus-5-5
translation_notes:
  - "结论 rendered as “Conclusion” and 证明 as “Proof”."
  - "带入 (sic) read as 代入, “substitute”."
  - "The author’s historical claims (1889, Cayley not finding the solution, “computer scientists”) are translated as written."
---

## Cayley's Theorem

**Conclusion**  The number of labeled unrooted trees with $n$ nodes is $n^{n-2}$.

This result shows up in many counting problems. To prove it, you first need to know about Prufer sequences. The proof is given below.

<!--more-->

**Proof**  Every tree can be converted into a Prufer sequence. By definition, the number of times each node appears in the Prufer sequence equals its degree minus one, that is, $d_i - 1$. The length of the whole Prufer sequence is $\sum_i d_i - 1 = 2(n -1) - n = n - 2$. The shapes of unrooted trees correspond one-to-one with Prufer sequences, so the number of unrooted trees also equals the number of Prufer sequences. Hence the count is $n^{n-2}$.

Cayley proved this theorem in 1889, and after proving it he posed a new problem:

> How many ways can $n$ nodes form a forest of $s$ trees?

Cayley was never able to find the solution to this problem afterward. Next, we introduce the “Extended Cayley Theorem”.

## Extended Cayley Theorem

Cayley proposed a possible solution to this problem:

$$
F(n, s) = sn^{n - s - 1}
$$

However, Cayley then set the problem aside, and did not manage to complete the proof before he died. In the last century, many computer scientists used many methods to prove it; I referred to the paper On Cayley’s Formula for Counting Forests by LAJOS TAKACS. Now I will retell it.

**Proof**   First, there is the recurrence:

$$
F(n, s) = \sum_{j = 0}^{n - s} {n - s \choose j} F(n - 1, s + j - 1)
$$

Let's prove this recurrence first. Suppose the node we are at is node 1, and enumerate $j$ as the number of children of node 1. For each $j$ there are $n - s \choose j$ ways to choose among the remaining nodes, and then we recurse: delete the node itself, and the number of ways for the $j$ children goes straight into the recursive subproblem, that is, $F(n - 1, s + j - 1)$. Substituting Cayley's conjectured formula proves it.
