40.01.07 · combinatorics / enumeration-generating-functions

Trees, Cayley's Formula, the Matrix-Tree Theorem, and Lagrange Inversion

shipped3 tiersLean: none

Anchor (Master): Stanley 1999 *Enumerative Combinatorics, Volume 2* (Cambridge) Ch. 5 in full — the tree function $T = xe^T$, Lagrange inversion (Theorem 5.4.2, Corollary 5.4.3), the matrix-tree theorem and its all-minors / weighted refinement (Theorem 5.6.8), and the BEST theorem for Eulerian circuits (Corollary 5.6.3 region); Flajolet-Sedgewick 2009 *Analytic Combinatorics* (Cambridge) Note I.49 and §VI.7 (Lagrange inversion, tree singularities); Tutte 1948 and Brooks-Smith-Stone-Tutte 1940 for the matrix-tree and BEST origins; Kirchhoff 1847 (the original Laplacian-cofactor count)

Intuition Beginner

A tree is the leanest way to keep a set of dots all connected: every dot reachable from every other, but with not one extra line. Cut any line and the tree falls into two pieces; add any line and you create a loop. Family trees, river systems, the folder structure on your computer — all of these are trees, and the surprising thing is not what one tree looks like but how many different trees you can build on a fixed set of labelled dots.

Here is the headline number. If you have labelled dots and you ask how many different trees join them all up, the answer is to the power . For three dots there are trees; for four dots there are ; for five dots there are . That clean formula, , is Cayley's formula, and a large part of this unit is four different ways of seeing why it is true. Each way teaches a separate lesson, which is why one formula deserves four proofs.

A second question is more practical. Given a specific network — a power grid, a road map, a circuit — how many ways are there to pick a skeleton of lines that keeps it connected with no loops? Such a skeleton is a spanning tree. Counting spanning trees turns out to be a determinant: you write down a simple matrix from the network and compute one cofactor. This is the matrix-tree theorem, and it converts a hard counting problem into a routine of linear algebra.

The third idea is a machine for inverting tree recipes. A tree is "a root with smaller trees hanging off it," a description that folds back on itself. Lagrange inversion is the algebraic crank that turns such self-referential recipes directly into counting formulas.

Visual Beginner

Picture the Prüfer encoding, the trick at the heart of the first proof of Cayley's formula. You take a labelled tree and repeatedly snip off the leaf with the smallest label, each time writing down the name of the dot it was attached to. Snip, record; snip, record. When only two dots remain you stop. A tree on dots gives a list of exactly recorded names, and — this is the magic — every possible list of that length comes from exactly one tree.

The table below runs the snipping on one small tree so you can follow the bookkeeping. Because each recorded list has length and each slot can hold any of the labels, the number of lists is with factors, which is — and that is the count of trees.

step smallest leaf removed neighbour recorded sequence so far
1 1 3 3
2 2 3 3, 3
3 4 5 3, 3, 5
4 3 5 3, 3, 5, 5
stop two dots left (5, 6) length 4 = 6 − 2

Worked example Beginner

Let us count the spanning trees of one small network by hand and then check the answer against the matrix-tree determinant. Take the triangle on three dots with all three sides drawn. How many spanning trees does it have?

Step 1. A spanning tree on dots needs exactly lines and must stay connected. The triangle has lines: side , side , side .

Step 2. Choosing of the sides to keep, and dropping one, gives three choices. Dropping any single side from a triangle still leaves a connected path through all three dots, so all three choices are valid spanning trees.

Step 3. The count is therefore . The three spanning trees are the paths , , and — each one a triangle with one side rubbed out.

Step 4. Check against the formula. The triangle is the complete network on dots, and Cayley's formula says a complete network on labelled dots has spanning trees. For that is . The hand count and the formula agree.

What this tells us: counting spanning trees by listing them works for tiny networks but explodes fast. For the count is , a hundred million — far too many to list. The matrix-tree theorem and Cayley's formula exist precisely so you never have to list them: you read the count off a determinant or a power.

Check your understanding Beginner

Formal definition Intermediate+

Throughout, a tree is a connected acyclic graph; the tree characterisations (connected with edges, acyclic with edges, unique paths) and the leaf-existence lemma are taken from 40.04.01. A rooted tree is a tree with one distinguished vertex, the root; orienting every edge toward (or away from) the root makes the parent-child structure explicit. A labelled tree on is a tree whose vertex set is ; two labelled trees are equal only if they have the same edge set as subsets of .

Definition (Prüfer sequence). Given a labelled tree on with , the Prüfer sequence is produced by iterating: while more than two vertices remain, let be the leaf of least label, append the label of 's unique neighbour to the sequence, and delete . The map records copies of each label .

Definition (the tree function). The tree function is the formal power series , the exponential generating function of rooted labelled trees ( of them on , one choice of root per labelled tree times trees). It is the unique series with satisfying the functional equation $$ T(x) = x,e^{T(x)}, $$ expressing "a rooted tree is a root vertex carrying a set (an EGF , per the exponential formula of 40.01.03) of root-subtrees." Differentiating gives , exhibiting the singularity at that 40.08.05 exploits.

Definition (Laplacian). For a graph on vertex set with adjacency matrix and degree-diagonal , the Laplacian is . Each row and column of sums to , so is singular; the reduced Laplacian is with row and column deleted. A weighted graph assigns to each edge and uses the weighted Laplacian off-diagonal, on the diagonal. The spanning-tree generating polynomial is , summed over spanning trees .

Counterexamples to common slips Intermediate+

  • "Any cofactor of the Laplacian could differ." All cofactors of (deleting row , column , with sign ) are equal, to . The signed cofactors agree because has all line-sums zero; deleting different rows and columns gives the same value, so "any cofactor" is well-defined.

  • "The eigenvalue formula uses all eigenvalues." The Laplacian always has eigenvalue (eigenvector ), so . The product is over the nonzero eigenvalues: . Including the zero eigenvalue would give .

  • "Lagrange inversion needs to be a polynomial." It needs only so that has a unique solution with and . Any formal power series with nonzero constant term works; (giving the tree function) is the canonical non-polynomial case.

  • "A Prüfer sequence determines the tree only up to relabelling." It determines the tree exactly. The degree of each vertex is recovered as one plus its multiplicity in the sequence, and the greedy leaf-reattachment reconstructs the unique tree; the map is a genuine bijection, not a quotient.

Key theorem with proof Intermediate+

The signature theorem is Cayley's formula, and it is stated here with the Prüfer bijection so that the same construction simultaneously delivers the degree-specified refinement.

Theorem (Cayley's formula, with degree refinement). For the number of labelled trees on is . More precisely, the number of labelled trees in which vertex has degree (with each and ) is the multinomial coefficient $$ \binom{n-2}{d_1 - 1, , d_2 - 1, , \dots, , d_n - 1} = \frac{(n-2)!}{\prod_{i=1}^n (d_i - 1)!}. $$ (Stanley [Stanley §5.3], Aigner-Ziegler [Aigner-Ziegler Ch. 33].)

Proof. The map sending a labelled tree on to its Prüfer sequence in is a bijection; granting this, counts the trees. The degree refinement is then immediate from the multiplicity property: in a label occurs exactly times, so trees with degree vector correspond to sequences of length containing label exactly times, and the number of such sequences is the multinomial coefficient .

It remains to prove is a bijection. Multiplicity property. Each time a vertex is recorded, it is because a neighbour of was just deleted as the least leaf; is recorded once per neighbour deleted while survives. A vertex is itself deleted only once its surviving degree falls to (it has become a leaf) and it is the least such, after which it is never recorded again. The two endpoints surviving at the end are never deleted. Counting, a non-final vertex loses all but one of its incident edges to neighbour-deletions before becoming a leaf and being deleted, contributing records; a final vertex loses all neighbours but is never deleted, also contributing records once one accounts for the last edge joining the two survivors. So every appears times.

Injectivity and surjectivity by an explicit inverse. Given any sequence , define a candidate degree by ; then , the correct edge-degree sum for a tree. Reconstruct as follows: maintain the multiset of "remaining" labels (initially all of ) and read left to right. At step , let be the least remaining label that does not occur in the suffix — this is the least current leaf — add the edge , and remove from the remaining labels. After steps, two labels remain; join them by the final edge. At each step a least non-occurring leaf exists because at most distinct labels can occur in a suffix of length , leaving a remaining label that is a leaf. The construction is forced at every step — the least leaf and its recorded neighbour are determined by — so it inverts and is single-valued. Hence is a bijection.

Corollary (rooted trees and the tree function). The number of rooted labelled trees on is , so the EGF counts them. The decomposition "root vertex plus a set of root-subtrees" gives via the exponential formula of 40.01.03, the functional equation inverted in the Advanced section.

Bridge. This theorem builds toward the entire analytic theory of tree-like structures and appears again in 40.08.05, where the singularity of at delivers the universal asymptotic law for simply generated trees. The foundational reason one formula admits four proofs is that is the value of four genuinely different functionals on the same object: a word count (Prüfer), a determinant (matrix-tree), a forest-refinement count (Pitman), and a coefficient of a fixed-point series (Lagrange on ). This is exactly the situation where a single integer carries several structures, and the Prüfer bijection generalises the degree refinement that the determinant cannot see, while the determinant generalises to arbitrary graphs that the bijection cannot reach. Putting these together, the central insight is that Cayley's count is the spanning-tree count of , so the matrix-tree theorem is the general statement of which Cayley's formula is the complete-graph instance, and the tree function is the generating-function packaging that ports the count into 40.08.05.

Exercises Intermediate+

Advanced results Master

Theorem 1 (matrix-tree theorem, weighted and all-minors form). Let be a connected graph (or multigraph) on with edge weights , weighted Laplacian , and let be with row and column deleted. Then $$ \det L_0 = \tau_w(G) = \sum_{T \text{ spanning tree}} ;\prod_{e \in T} w_e . $$ Unweighted () this is the spanning-tree count, equal to any signed cofactor of . The all-minors generalisation expresses an arbitrary minor of — deleting a set of rows and of columns with — as a signed sum of weights of spanning forests whose trees each contain one prescribed vertex of and one of [Stanley §5.6].

Proof sketch (Cauchy-Binet). Orient each edge arbitrarily and form the signed incidence matrix with if is the head of , if the tail, otherwise; for weights, scale column by . Then . Deleting row from gives with . By Cauchy-Binet, $$ \det L_0 = \det(N_0 N_0^\top) = \sum_{\substack{S \subseteq E \ |S| = n-1}} \det\big(N_0[S]\big)^2 \quad(\text{weighted: }\textstyle\prod_{e\in S}w_e), $$ the sum over -subsets of edges. The square submatrix has determinant when is the edge set of a spanning tree and otherwise — because an -edge subgraph on vertices is a spanning tree iff it is acyclic iff its incidence columns are linearly independent, and a tree, processed leaf-first, makes triangular with unit diagonal. Each spanning tree contributes (weighted: ), giving .

Theorem 2 (the eigenvalue formula). For a connected graph on vertices with Laplacian eigenvalues , the number of spanning trees is [Stanley §5.6]. The Laplacian's characteristic polynomial is ; the coefficient of is (only the term survives since ), and the same coefficient equals times the sum of the principal minors of , namely since each of the principal cofactors equals . Equating gives .

Theorem 3 (Lagrange-Bürmann inversion). Let with , and let be the unique series with solving . For any formal Laurent series and , $$ [x^n],H(R(x)) ;=; \frac{1}{n},[\lambda^{n-1}]\Big(H'(\lambda),\phi(\lambda)^n\Big), \qquad\qquad [x^n],R(x) = \frac{1}{n},[\lambda^{n-1}],\phi(\lambda)^n, $$ and in residue form where is the compositional inverse of [Stanley §5.4], [Flajolet-Sedgewick Note I.49]. Applied to it gives (rooted trees), to and the Catalan numbers, and to ballot/cycle-lemma weightings the Catalan and ballot-number refinements.

Theorem 4 (the BEST theorem). In a connected Eulerian digraph (every vertex has ), the number of Eulerian circuits, counted up to starting point, is $$ \mathrm{ec}(G) = t_w(G),\prod_{v \in V}\big(\deg^+(v) - 1\big)!, $$ where is the number of arborescences rooted at (any fixed) vertex — itself a directed-Laplacian cofactor, independent of [Stanley §5.6]. The name abbreviates de Bruijn, van Aardenne-Ehrenfest, Smith, and Tutte. The proof pairs an Eulerian circuit with the arborescence of "last exit edges": for each vertex, the last edge used to leave it before the circuit closes forms a spanning in-tree toward , and conversely each arborescence together with an ordering of the remaining out-edges at each vertex reconstructs a unique circuit, giving the product of local factorials.

Theorem 5 (Joyal's proof and the doubly-rooted bijection). The identity holds via a bijection, whence the number of (singly) rooted trees is and of trees is [Aigner-Ziegler Ch. 33]. A function is a functional digraph whose connected components each have one cycle with trees hanging off; replacing the cyclic part (a permutation of the cyclic vertices) by the linear order it induces converts the structure into a tree with two marked vertices (a vertebrate: head and tail of the spine). The two markings supply the two extra factors of , so trees number .

Synthesis. The four proofs of Cayley's formula are the foundational reason this unit sits at the centre of the chapter: each computes as a different functional, and putting these together the Prüfer word count, the Laplacian determinant, Pitman's forest refinement, and the Lagrange coefficient of are four readings of one integer, exactly as the OGF and EGF were two readings of one sequence in 40.01.03. The central insight is that Cayley's count is the spanning-tree count of , so the matrix-tree theorem generalises it to every weighted graph, and the eigenvalue product is dual to the cofactor determinant through the characteristic polynomial — the same number read off the spectrum or off a minor. This is exactly the duality that the BEST theorem exploits one level up: Eulerian circuits of a digraph are counted by arborescences, which are directed spanning trees counted by a directed-Laplacian cofactor, so circuit enumeration reduces to the same determinant. Lagrange inversion is the generating-function engine binding all of this to 40.08.05: it converts the fixed-point equation into the explicit , and its residue form is what the singularity analysis of 40.08.05 differentiates to obtain the tree-asymptotic law. The bridge is that every count here — the word, the determinant, the spectrum, the circuit, the coefficient — is one of these four functionals evaluated on the tree object, and the analytic continuation of the last functional is the gateway to asymptotics.

Full proof set Master

Proposition 1 (Prüfer is a bijection; Cayley's formula). The map from labelled trees on to is a bijection, so there are labelled trees.

Proof. Multiplicity: in the leaf-pruning process, a vertex is recorded exactly once for each incident edge lost to the deletion of a neighbour, and is deleted exactly when its surviving degree reaches (after which it is recorded no more, and the final two vertices are never deleted). Each non-final vertex thus contributes records; bookkeeping the last edge between the two survivors shows each final vertex also contributes . Hence label appears times, and matches the sequence length. Inverse: given , set , which sums to . Read left to right; at step the least label not occurring in the suffix and not yet deleted is the unique forced least leaf , and we add edge and delete ; a least such leaf exists because fewer than the number of remaining labels can occur in the strictly shorter suffix. Two labels survive and are joined by the last edge. The resulting graph has edges and is connected and acyclic by induction (each step attaches a leaf to a smaller tree-in-progress), hence a tree, and the construction is the unique pre-image of . So is a bijection and the tree count is .

Proposition 2 (matrix-tree theorem). For a connected graph on , for the reduced Laplacian with any one row and the same column removed; weighting edges by replaces by .

Proof. Orient edges arbitrarily; let be the signed incidence matrix (column has at the head, at the tail), with column scaled by in the weighted case. Then equals when and when , i.e. . Delete row : . Cauchy-Binet expands (weighted: times ). For an -subset of edges, the submatrix is ; if contains a cycle, the alternating sum of the cycle's incidence columns vanishes, so the columns are dependent and the determinant is . If is acyclic with edges it is a spanning tree; processing its leaves successively (each leaf gives a row with a single nonzero entry ) shows is, after row/column permutation, triangular with diagonal, so and its square is . Summing, only spanning trees contribute, each with weight , giving . Equality of all signed cofactors of follows from and , forcing constant.

Proposition 3 (Lagrange inversion, residue proof). With and , , one has for .

Proof. The compositional inverse of is , since rearranges to . The formal residue annihilates derivatives ( for ) and is invariant under formal change of variable. Write ; then . Substitute , , : $$ [x^n]H(R) = \mathrm{Res}\lambda\big(\psi(\lambda)^{-n-1}H(\lambda),\psi'(\lambda)\big). $$ Now , so integrating by parts (using ), $$ [x^n]H(R) = -\frac1n\mathrm{Res}\lambda\Big(H(\lambda)\tfrac{d}{d\lambda}\psi^{-n}\Big) = \frac1n\mathrm{Res}\lambda\big(H'(\lambda)\psi(\lambda)^{-n}\big) = \frac1n[\lambda^{n-1}]\big(H'(\lambda)\phi(\lambda)^n\big), $$ since and $\mathrm{Res}\lambda(g(\lambda)\lambda^{-n}) = [\lambda^{n-1}]gH(\lambda) = \lambda[x^n]R = \frac1n[\lambda^{n-1}]\phi(\lambda)^n\square$

Proposition 4 (Cayley via the tree function). The rooted-tree EGF has , so there are rooted and unrooted labelled trees.

Proof. Apply Proposition 3 with (so ): . Expanding , the coefficient of is , so . The number of rooted trees on is ; dividing by the choices of root gives unrooted trees, consistent with Proposition 1.

Proposition 5 (directed matrix-tree / Markov-chain-tree, used by BEST). Let be a digraph and its out-Laplacian (diagonal of out-degrees minus the adjacency). The principal cofactor deleting row and column equals the number of spanning arborescences oriented toward , independent of the off-root deletion.

Proof. The argument mirrors Proposition 2 with the directed incidence structure. Each spanning arborescence toward is an acyclic out-degree-one-off- subgraph; the Cauchy-Binet / cofactor expansion of with row and column removed selects exactly the edge sets in which every vertex except has out-degree and which are acyclic, i.e. the arborescences rooted at , each contributing . Independence of follows because the all-ones vector is a left null vector of (each row of sums to the out-degree), so by the adjugate argument the relevant cofactors are equal across roots. This is the arborescence count entering the BEST product , whose bijective core is the last-exit-tree correspondence stated in Theorem 4.

Connections Master

  • The tree function assembled here is the exact object whose analytic continuation drives 40.08.05: that unit locates the dominant singularity of at (where and the square-root branch of the inverse appears), and singularity analysis converts the coefficient into Stirling-asymptotic form and then into the universal law for simply generated families of trees. This unit owns the exact enumeration and the fixed-point equation; 40.08.05 owns the coefficient asymptotics that the residue form of Lagrange inversion feeds.

  • The graph Laplacian and its cofactor/eigenvalue spanning-tree counts are the combinatorial source of spectral graph theory: the matrix-tree eigenvalue product , the multiplicity of the eigenvalue counting components, and the algebraic connectivity all read graph structure off the Laplacian spectrum. The foundational graph object — degrees, adjacency, the handshake count — comes from 40.04.01, which co-produces the basic tree characterisations this unit's enumeration rests on; the matrix-tree theorem is the determinantal lift of that unit's Cayley preview into arbitrary weighted graphs.

  • Lagrange inversion and the Catalan instance tie directly back to 40.01.03, where the Catalan generating function was solved by the quadratic and the exponential formula gave as the set-of-subtrees construction; this unit supplies the inversion theorem that 40.01.03 previewed on and the Catalan quadratic. The OGF/EGF symbolic dictionary of 40.01.03 — the SET row giving , the sequence row giving — is what makes "rooted tree = root + set of subtrees" translate to the functional equation that Lagrange inversion then solves in closed form.

Historical & philosophical context Master

The count was published by Arthur Cayley in 1889, A theorem on trees (Quarterly Journal of Pure and Applied Mathematics 23, 376–378), in the course of enumerating rooted trees and chemical isomers; Cayley's own argument was a recursive generating-function count rather than a bijection. The bijective encoding now universally taught is due to Heinz Prüfer (1918), Neuer Beweis eines Satzes über Permutationen (Archiv der Mathematik und Physik 27, 142–144), which gave the leaf-pruning correspondence and with it the degree-specified refinement [Aigner-Ziegler Ch. 33].

The determinantal count is older than Cayley's formula: Gustav Kirchhoff (1847), Über die Auflösung der Gleichungen, auf welche man bei der Untersuchung der linearen Vertheilung galvanischer Ströme geführt wird (Annalen der Physik 72, 497–508), derived the spanning-tree cofactor identity while computing currents in resistive networks, so the matrix-tree theorem entered mathematics through physics. James Joyal's 1981 theory of species [Stanley §5.4] supplied the doubly-rooted "vertebrate" bijection proving by the functional identity , and Jim Pitman's 1999 double-counting of refining forests gave the fourth proof by counting the ways to grow a tree edge by edge in two orders. Lagrange's 1770 reversion of series is the analytic ancestor of the inversion theorem, given its residue form by Bürmann (1799) and folded into enumerative combinatorics through the symbolic method of Flajolet and Sedgewick [Flajolet-Sedgewick Note I.49]. The Eulerian-circuit count is the BEST theorem, after de Bruijn and van Aardenne-Ehrenfest (1951) and Smith and Tutte (1941), uniting the arborescence count of the directed matrix-tree theorem with the local factorial orderings.

Bibliography Master

@book{stanley1999ec2,
  author    = {Stanley, Richard P.},
  title     = {Enumerative Combinatorics, Volume 2},
  series    = {Cambridge Studies in Advanced Mathematics},
  volume    = {62},
  publisher = {Cambridge University Press},
  year      = {1999}
}

@book{aignerziegler2018book,
  author    = {Aigner, Martin and Ziegler, G\"unter M.},
  title     = {Proofs from THE BOOK},
  edition   = {6},
  publisher = {Springer},
  year      = {2018}
}

@book{flajoletsedgewick2009,
  author    = {Flajolet, Philippe and Sedgewick, Robert},
  title     = {Analytic Combinatorics},
  publisher = {Cambridge University Press},
  year      = {2009}
}

@book{vanlintwilson2001,
  author    = {van Lint, J. H. and Wilson, R. M.},
  title     = {A Course in Combinatorics},
  edition   = {2},
  publisher = {Cambridge University Press},
  year      = {2001}
}

@article{cayley1889trees,
  author  = {Cayley, Arthur},
  title   = {A theorem on trees},
  journal = {Quarterly Journal of Pure and Applied Mathematics},
  volume  = {23},
  year    = {1889},
  pages   = {376--378}
}

@article{prufer1918,
  author  = {Pr\"ufer, Heinz},
  title   = {Neuer Beweis eines Satzes \"uber Permutationen},
  journal = {Archiv der Mathematik und Physik},
  volume  = {27},
  year    = {1918},
  pages   = {142--144}
}

@article{kirchhoff1847,
  author  = {Kirchhoff, Gustav},
  title   = {\"Uber die Aufl\"osung der Gleichungen, auf welche man bei der Untersuchung der linearen Vertheilung galvanischer Str\"ome gef\"uhrt wird},
  journal = {Annalen der Physik},
  volume  = {148},
  year    = {1847},
  pages   = {497--508}
}

@article{pitman1999forests,
  author  = {Pitman, Jim},
  title   = {Coalescent random forests},
  journal = {Journal of Combinatorial Theory, Series A},
  volume  = {85},
  year    = {1999},
  pages   = {165--193}
}