Olympiad in Informatics

Cayley's Theorem & the Extended Cayley Theorem

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.

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.