# 组合数学 (Spring 2015)/Cayley's formula

## Contents

## Cayley's Formula

We now present a theorem of the number of labeled trees on a fixed number of vertices. It is due to Cayley in 1889. The theorem is often referred by the name Cayley's formula.

**Cayley's formula for trees**- There are different trees on distinct vertices.

The theorem has several proofs, including the bijection which encodes a tree by a Prüfer code, through the Kirchhoff's matrix tree theorem, and by double counting.

### Proof of Cayley's formula by double counting

We now present a double counting proof, which is considered by the Proofs from THE BOOK "the most beautiful of them all".

**Proof of Cayley's formula by double counting**(Due to Pitman 1999)

Let be the number of different trees defined on distinct vertices.

A

**rooted tree**is a tree with a special vertex. That is, one of the vertices is marked as the "root" of the tree. A rooted tree defines a natural direction of all edges, such that an edge of the tree is directed from to if is before along the unique path from the root.We count the number of different

*sequences*of directed edges that can be added to an empty graph on vertices to form from it a*rooted*tree. We note that such a sequence can be formed in two ways:- Starting with an unrooted tree, choose one of its vertices as root, and fix an total order of edges to specify the order in which the edges are added.
- Starting from an empty graph, add the edges one by one in steps.

In the first method, we pick one of the unrooted trees, choose one of the vertices as the root, and pick one of the total orders of the edges. This gives us ways.

In the second method, we consider the number of choices in one step, and multiply the numbers of choices in all steps. This is done as follows.

Given a sequence of

*adding*edges to an empty graph to form a rooted tree, we reverse this sequence and get a sequence of*removing*edges one by one from the final rooted tree until no edge left. We observe that:- At first, we remove an edge from the rooted tree. Suppose that the root of the tree is , and the removed directed edge is . After removing , the original rooted tree is disconnected into two rooted trees, one rooted at and the other rooted at .
- After removing edges, there are rooted trees. In the th step, a directed edge in the current forest is removed and the tree containing is disconnected into two trees, one rooted at the old root of that tree, and the other rooted at .

We now again reverse the above procedure, and consider the sequence of adding directed edges to an empty graph to form a rooted tree.

- At first, we have rooted trees, each of 0 edge ( isolated vertices).
- After adding edges, there are rooted trees. Denoting the directed edge added next as . As observed above, can be any one of the vertices; but must be the root of one of the trees, except the tree which contains . There are choices of such .

Multiplying the numbers of choices in all steps, the number of sequences of adding directed edges to an empty graph to form a rooted tree is given by

- .

By the principle of double counting, counting the same thing by different methods yield the same result.

- ,

which gives that .

## Prüfer code

The Prüfer code encodes a labeled tree to a sequence of labels. This gives a bijections between trees and tuples.

### Encoding

In a tree, the vertices of degree 1 are called leaves. It is easy to see that:

- each tree has at least two leaves; and
- after removing a leaf (along with the edge adjacent to it) from a tree, the resulting graph is still a tree.

The following algorithm transforms a tree of vertices , to a tuple .

**Prüfer code (encoder)****Input**: A tree of distinct vertices, labeled by .- let ;
- for to , do
- let be the leaf in with the smallest label, and be its neighbor;
- let be the new tree obtained from deleting the leaf from ;

- end
- return ;

### Decoding

It is trivial to observe the following lemma:

**Lemma 1**- For each , is a tree of vertices. In particular, the vertices of are , and the edges of are precisely , .

And there is a reason that we do not need to store in the Prüfer code.

**Lemma 2**- It always holds that .

**Proof.**Every tree (of at least two vertices) has at least two leaves. The , , are the leaf of the smallest label in , which can never be , thus is never deleted.

Lemma 1 and 2 together imply that given a Prüfer code , the only remaining task to reconstruct the tree is to figure out those , . The following lemma state how to obtain , , from a Prüfer code .

**Lemma 3**- For , is the smallest element of not in .

**Proof.**Note that is a sequence of distinct vertices, because are deleted one by one from the tree, and is never deleted. Thus, each vertex appears among exactly once. And each vertex appears for times among the edges , , where denotes the degree of vertex in the original tree . Therefore, each vertex appears among for times.

Similarly, each vertex of appears among for times, where is the degree of vertex in the tree . In particular, the leaves of are not among . Recall that the vertices of are . Then the leaves of are the elements of not in . By definition of Prüfer code, is the leaf in of smallest label, hence the smallest element of not in .

Applying Lemma 3, we have the following decoder for the Prüfer code:

**Prüfer code (decoder)****Input**: A tuple .- let be empty graph, and ;
- for to , do
- let be the smallest label not in ;
- add an edge to ;

- end
- return ;

In other words, the encoding of trees to tuples by the Prüfer code is reversible, thus the mapping is injective (1-1). To see it is also surjective, we need to show that for every possible , the above decoder recovers a tree from it.

It is easy to see that the decoder always returns a graph of edges on the vertices. The only thing remaining to verify is that the returned graph has no cycle in it, which can be easily proved by a timeline argument (left as an exercise).

### Bijection proof of Cayley's formula

Therefore, the Prüfer code establishes a bijection between the set of trees on distinct vertices and the tuples from . This proves Cayley's formula.

## Kirchhoff's Matrix-Tree Theorem

Given an undirected graph , the **adjacency matrix** of graph is an matrix such that

### Graph Laplacian

Let be a diagonal matrix such that

where denotes the degree of vertex .

The **Laplacian matrix** of graph is defined as , that is,

Suppose has edges. The **incidence matrix** of graph is an matrix such that

The following proposition is easy to verify.

**Proposition**- .

**Proof.**For any , we have

- .

It is easy to verify that

which is equal to the definition of .

### The Matrix-tree Theorem

The matrix-tree theorem of Kirchhoff states a striking fact: The number of spanning trees in any connected graph can be computed as the determinant of some appropriate graph matrix.

**Kirchhoff's Matrix-Tree Theorem**- For any connected graph of vertices, the number of spanning trees in is for all , where is the matrix resulting from the Laplacian matrix of graph by deleting the -th row and the -th column.

The determinant can be computed as fast as matrix multiplication, thus is quite efficient, especially when compared to our task: counting the number of subgraphs satisfying certain nontrivial global constraint (e.g. spanning tree). Such efficient algorithm is rarely seen for counting problems, which are usually #P-hard to compute (e.g. number of matchings in a graph).

The key to prove the matrix-tree theorem is the Cauchy-Binet theorem in linear algebra, whose proof is beyond the scope of this class.

**Cauchy-Binet Theorem**- Let and be, respectively, and matrix. For any of size , let and denote, respectively, the submatrices of and , consisting of the columns of , or the rows of , indexed by elements of . Then

- Let and be, respectively, and matrix. For any of size , let and denote, respectively, the submatrices of and , consisting of the columns of , or the rows of , indexed by elements of . Then

Let be the incidence matrix of graph . Fix any vertex , let be the matrix resulting from by deleting the -th row.

Recall that . It is easy to verify that

Due to the Cauchy-Binet Theorem, we have

The next lemma gives a key observation to prove the matrix-tree theorem.

**Lemma**- For any of size , the value of is either 1, or -1, or 0. Moreover, if and only if indicates a spanning tree in .

**Proof.**We first show by induction on . Note that is an matrix such that each column contains at most one 1 and at most one -1, and all other entries are 0. For such matrix, when , the induction hypothesis is trivially true. And for general , if every column has a 1 and a -1, then the sum of all rows is the zero vector, so the matrix is singular. Otherwise, expand the determinant by a column with one nonzero entry to find it is times the determinant of a smaller matrix of the same property, which by induction hypothesis has value 0 or .

We then show that is nonzero if and only if is a spanning tree.

Suppose the edges corresponding to is not a spanning tree of . Then must have more than one components, and there must be a component not containing vertex . The rows of corresponding to add to 0, thus these rows are linearly dependent, and hence .

Suppose the edges corresponding to is a spanning tree of . Then there is a vertex of degree 1 in ; let be the edge in incident to . Deleting vertex and edge from , we obtain a tree of edges. Again there is a vertex of degree 1 with incident edge . Continue this we enumerate all vertices except as and all edges in as . Now permute the rows and columns of such that the -th row corresponds to vertex and the -th column corresponds to . By our construction the permuted is lower triangle with diagonal entries, since when each is removed it is of degree 1 in the remaining tree and is incident to edge . Therefore, .

The matrix-tree theorem follows as consequence. Recall we show that

The sum enumerates over all subgraphs of edges, and by the above lemma if and only if is a spanning tree in . Therefore, gives the number of spanning trees in .

### Cayley's formula by the matrix-tree theorem

The number of trees of distinct vertices equals the number of spanning trees in the complete graph . For , for any the matrix is given by

whose determinant is .