$\newcommand{\set}{\{1,2,\dotsc,#1\,\}} \newcommand{\ints}{\mathbb{Z}} \newcommand{\posints}{\mathbb{N}} \newcommand{\rats}{\mathbb{Q}} \newcommand{\reals}{\mathbb{R}} \newcommand{\complexes}{\mathbb{C}} \newcommand{\twospace}{\mathbb{R}^2} \newcommand{\threepace}{\mathbb{R}^3} \newcommand{\dspace}{\mathbb{R}^d} \newcommand{\nni}{\mathbb{N}_0} \newcommand{\nonnegints}{\mathbb{N}_0} \newcommand{\dom}{\operatorname{dom}} \newcommand{\ran}{\operatorname{ran}} \newcommand{\prob}{\operatorname{prob}} \newcommand{\Prob}{\operatorname{Prob}} \newcommand{\height}{\operatorname{height}} \newcommand{\width}{\operatorname{width}} \newcommand{\length}{\operatorname{length}} \newcommand{\crit}{\operatorname{crit}} \newcommand{\inc}{\operatorname{inc}} \newcommand{\HP}{\mathbf{H_P}} \newcommand{\HCP}{\mathbf{H^c_P}} \newcommand{\GP}{\mathbf{G_P}} \newcommand{\GQ}{\mathbf{G_Q}} \newcommand{\AG}{\mathbf{A_G}} \newcommand{\GCP}{\mathbf{G^c_P}} \newcommand{\PXP}{\mathbf{P}=(X,P)} \newcommand{\QYQ}{\mathbf{Q}=(Y,Q)} \newcommand{\GVE}{\mathbf{G}=(V,E)} \newcommand{\HWF}{\mathbf{H}=(W,F)} \newcommand{\bfC}{\mathbf{C}} \newcommand{\bfG}{\mathbf{G}} \newcommand{\bfH}{\mathbf{H}} \newcommand{\bfF}{\mathbf{F}} \newcommand{\bfI}{\mathbf{I}} \newcommand{\bfK}{\mathbf{K}} \newcommand{\bfP}{\mathbf{P}} \newcommand{\bfQ}{\mathbf{Q}} \newcommand{\bfR}{\mathbf{R}} \newcommand{\bfS}{\mathbf{S}} \newcommand{\bfT}{\mathbf{T}} \newcommand{\bfNP}{\mathbf{NP}} \newcommand{\bftwo}{\mathbf{2}} \newcommand{\cgA}{\mathcal{A}} \newcommand{\cgB}{\mathcal{B}} \newcommand{\cgC}{\mathcal{C}} \newcommand{\cgD}{\mathcal{D}} \newcommand{\cgE}{\mathcal{E}} \newcommand{\cgF}{\mathcal{F}} \newcommand{\cgG}{\mathcal{G}} \newcommand{\cgM}{\mathcal{M}} \newcommand{\cgN}{\mathcal{N}} \newcommand{\cgP}{\mathcal{P}} \newcommand{\cgR}{\mathcal{R}} \newcommand{\cgS}{\mathcal{S}} \newcommand{\bfn}{\mathbf{n}} \newcommand{\bfm}{\mathbf{m}} \newcommand{\bfk}{\mathbf{k}} \newcommand{\bfs}{\mathbf{s}} \newcommand{\bijection}{\xrightarrow[\text{onto}]{\text{1--1}}} \newcommand{\injection}{\xrightarrow[]{\text{1--1}}} \newcommand{\surjection}{\xrightarrow[\text{onto}]{}} \newcommand{\nin}{\not\in} \newcommand{\prufer}{\mbox{prüfer}} \DeclareMathOperator{\fix}{fix} \DeclareMathOperator{\stab}{stab} \DeclareMathOperator{\var}{var} \newcommand{\inv}{^{-1}} \newcommand{\lt}{<} \newcommand{\gt}{>} \newcommand{\amp}{&}$

## Section3.4Prüfer Codes

This section covers the Prüfer Code, a bijection between labelled trees and certain sequences of integers. This bijection allows us to prove Cayley's theorem, giving a count of such labelled trees.

Given a combinatorial structure, such as a graph or a tree, it is natural to ask how many of such structures there are. Often, there is no nice formula, for instance, for the number of different trees on $n$ vertices there. But if the vertices are labelled, then it turns out there's a nice answer.

###### Definition3.4.1Labelled tree

A labelled tree on $n$ vertices is a tree with $n$ vertices, which are labelled $1,2,\dots,n.$

One more convenient way of writing down a labelled tree is to write down all the edges. If there tree has $n$ vertices, then there are $n-1$ edges, and writing down all the edges takes $2n-2$ numbers between $1...n\text{.}$ However, we see that we're writing down the same tree lots of different times, by changing the order of the edges, and which vertex from each edge we write first. Furthermore, not every sequence of $2n-2$ numbers between $1...n$ will result in a tree.

To fix this problem, we will write down the edges in a particular order. Every tree has at least two leaves, and deleting a leaf gives a small tree. We will use these facts to give a systematic ordering to the edges in a labelled tree, as follows: the first edge will be the edge connecting the leaf with the smallest label to the rest of the tree. We will record that edge, with the leaf on the bottom row, and the "parent" vertex, i.e., the vertex the leaf is connected to, in the top row. Deleting the leaf and the vertex gives a tree with one fewer vertex, and we iterate the process.

This method fixes the problem of the ordering of the edges not being unique, but as of now we are still recording more information than needed. But note the following: since we delete a vertex when we put it in the bottom row, no number will appear twice on the bottom row. The last column is the last two vertices existing, and if we look at the bottom row and the last entry on the top row, we see that every number from 1 to $n$ will appear exactly once in these spots.

###### Definition3.4.4Prüfer code

If record the edges of a tree $T$ as in the Pruning Algorithm, the first $n-2$ number appear in the top row is the Prüfer code of $T$

To finish the proof of Cayley's Theorem, we need to show that the Prüfer code is a bijection. The easiest way to do this is to show that it has an inverse; that is, given any sequence of $n-2$ numbers between 1 and $n\text{,}$ we can construct a tree $T$ have that sequence as its Prüfer code.

This is most easily done by filling in the $n$ numbers we deleted from the table of edges to get the Prüfer code. We will in the numbers on the bottom row from left to right. The first number on the bottom row will be the lowest number that does not appear in the Prüfer code. Delete the first column, and then iterate -- the next number will be the lowest number we haven't used, and that doesn't appear in the remainder of the Prüfer code.

Another way to phrase the last line, is that the next number filled in is always the lowest number the doesn't appear as the bottom entry on one of the $n-1$ columns.

Suppose $T$ has Prüfer code 4,4,1,4,5,5. This code has length 6, so we looking to complete it by filling in numbers from 1 to 8. We illustrate the process step by step.

The lowest number that doesn't appear is 2, so we fill that in on the bottom of the first column. We no longer have to consider the 4 directly above this 2, as it is not the bottom element of its column.

 4 4 1 4 5 5 2

To fill in the next cell, we put the lowest number not occuring as the lowest element of a column, namely 3.

 4 4 1 4 5 5 2 3

And now the lowest term not on the bottom of its column is 6, so we add that:

 4 4 1 4 5 5 2 3 6

Now the only 1 appearing has an element beneath it, and so 1 gets added in the next column:

 4 4 1 4 5 5 2 3 6 1

And now all the 4s have been passed, so the next number is 4. We jump ahead and fill in the two numbers under 5 as well:

 4 4 1 4 5 5 2 3 6 1 4 7

The two numbers we haven't used yet are 5 and 8, so they are the entries in the last column, giving us the completed table of edges

 4 4 1 4 5 5 8 2 3 6 1 4 7 5

Having constructed the table encoding all the edges, we can now draw the labelled tree with those edges