Cayley's Formula and Matrix-Tree Theorem

How many distinct trees can you build on a fixed set of labeled points? For n=4n=4 points, the answer is exactly 1616. For general nn, it is the astonishingly clean number nn−2n^{n-2}. This is Cayley's formula, one of the most quoted enumerative facts in combinatorics. The surprise is not just the answer but the sheer number of unrelated proofs it admits. These include bijective, recursive, generating-functional, and algebraic approaches. Counting trees matters because trees are the skeleton of connectivity. Every connected graph contains one. Understanding how many spanning subtrees a graph has is a question about structure. It concerns its structural redundancy, its reliability as a network, and (as later theory will show) its spectrum. The deeper and more powerful tool in this article is the Matrix-Tree Theorem of Kirchhoff. It answers a vastly more general question. Given any labeled graph GG, not just the complete graph, how many Spanning Trees does it have? Kirchhoff's remarkable insight, discovered in the 1840s while analyzing electrical circuits, is striking. This purely combinatorial count is encoded as a single determinant of a matrix built from the graph — the Laplacian. Cayley's formula turns out to be the special case of Kirchhoff's theorem applied to the complete graph KnK_n. So the general theorem strictly subsumes and explains the specific one. The big picture is a bridge between two worlds. These are combinatorics (counting discrete objects) and linear algebra (determinants, eigenvalues, cofactors). This bridge is the entry point to spectral graph theory. There, the eigenvalues of the Laplacian encode expansion, connectivity, and random walk behavior of a graph. The Matrix-Tree Theorem is the first and cleanest example of a "spectral" quantity. A determinant computes a combinatorial invariant exactly, with no approximation and no hidden constants. This article gives Cayley's formula with a complete bijective proof via Prüfer sequences. It then develops the Laplacian matrix and proves the Matrix-Tree Theorem in full, using the Cauchy–Binet formula. We verify both results on explicit small graphs. We discuss exactly which hypotheses (connectedness, labeling) are load-bearing. It closes with the theorem's role as the gateway to spectral methods.

Key takeaways
  • Cayley's formula: the number of labeled trees on n≥1n \ge 1 vertices is nn−2n^{n-2} (for n≥2n\ge 2; the count is 11 when n=1n=1).
  • Prüfer's bijection converts each labeled tree into a unique sequence in {1,…,n}n−2\{1,\dots,n\}^{n-2}, giving an exact, constructive proof.
  • The Laplacian matrix L=D−AL = D - A of a graph packages degrees and adjacency into one symmetric matrix.
  • The Matrix-Tree Theorem: any cofactor of LL equals the number of spanning trees of GG, for any connected or disconnected labeled graph.
  • Applying the theorem to KnK_n recovers Cayley's formula as a determinant computation, unifying both results.
  • Key idea: counting spanning trees, a purely combinatorial problem, is exactly solved by a single determinant of a linear-algebraic object built from the graph.

Where this lives today

The Matrix-Tree Theorem is a computational workhorse: counting spanning trees of a network graph in polynomial time (via Gaussian elimination on the Laplacian cofactor) versus the naive exponential enumeration of subsets of edges. This matters directly in electrical engineering, where Kirchhoff's original motivation persists — the theorem underlies formulas for effective resistance between nodes in a resistor network, a quantity computable directly from Laplacian cofactors and closely tied to random walks on graphs. In statistical physics, the number of spanning trees of a lattice graph is related to the partition function of the q-state Potts model in a certain limit (q→0q \to 0), linking tree enumeration to phase transitions. In computer science, spanning tree counts and the Laplacian appear in network reliability analysis (a proxy for how many ways a network stays connected), in algorithms for generating uniformly random spanning trees (used in maze generation and in approximation algorithms), and in the design of expander-based error-correcting codes. In cryptography and algorithm design, the Laplacian's determinant structure supports fast algorithmic counting subroutines used within combinatorial optimization. Perhaps most importantly for the sequence of ideas this article sits in, the Laplacian's cofactors are only the first fingerprint of the richer object: its full eigenvalue spectrum, which is the subject taken up next in the passage toward Introduction to Spectral Graph Theory, where the same matrix LL used here to count trees is shown to encode graph connectivity (via its second-smallest eigenvalue, the algebraic connectivity), expansion, and mixing times of random walks — all consequences of the same object introduced here purely to count spanning trees.

Ask the tutor: How does the Matrix-Tree Theorem generalize to compute effective resistance between two specific vertices in a weighted network?

Cayley's Formula and the Matrix-Tree Theorem

DefinitionLabeled Tree, Laplacian Matrix, and Cofactor

Let [n]={1,2,…,n}[n] = \{1, 2, \dots, n\}. A labeled tree on [n][n] is a tree T=([n],E)T = ([n], E) whose vertex set is exactly [n][n]; two labeled trees are considered different if their edge sets differ, even if they are isomorphic as abstract graphs. Let G=(V,E)G = (V, E) be a simple graph with V=[n]V = [n] (loops and multiple edges excluded unless stated). The degree matrix DD is the n×nn \times n diagonal matrix with Dii=deg⁡(i)D_{ii} = \deg(i). The adjacency matrix AA has Aij=1A_{ij} = 1 if ij∈Eij \in E and Aij=0A_{ij} = 0 otherwise (with Aii=0A_{ii} = 0). The Laplacian matrix of GG is

L(G)=D−A.L(G) = D - A.

Equivalently, Lii=deg⁡(i)L_{ii} = \deg(i) and Lij=−1L_{ij} = -1 if ij∈Eij \in E, Lij=0L_{ij}=0 if i≠ji \ne j and ij∉Eij \notin E. For 1≤i≤n1 \le i \le n, the ii-th cofactor of LL is

Ci=(−1)i+idet⁡(L(i))=det⁡(L(i)),C_i = (-1)^{i+i}\det\big(L^{(i)}\big) = \det\big(L^{(i)}\big),

where L(i)L^{(i)} is the (n−1)×(n−1)(n-1)\times(n-1) matrix obtained by deleting row ii and column ii from LL.

Intuition

Cayley's number nn−2n^{n-2} looks too simple to be an accident, and indeed it has a combinatorial engine behind it: a labeled tree on nn vertices is completely determined by, and can be recovered from, a sequence of n−2n-2 labels from [n][n] (repeats allowed). This is the Prüfer sequence. Building a tree is equivalent to filling in n−2n-2 blanks, each with nn choices, giving nn−2n^{n-2} possibilities — as long as we can show the correspondence is a genuine bijection, which is the content of the proof below. The Laplacian generalizes this counting problem from KnK_n to an arbitrary graph GG. Think of LL as encoding "each vertex pushes away from itself along its edges": the row for vertex ii has +deg⁡(i)+\deg(i) on the diagonal and −1-1 at each neighbor, so every row sums to zero. This zero row-sum means LL is always singular (1\mathbf{1} is in its kernel), so det⁡L=0\det L = 0 always — the full determinant carries no information. The content of Kirchhoff's theorem is that if you delete any one row and the matching column, the resulting (n−1)×(n−1)(n-1)\times(n-1) determinant is no longer trivially zero, and in fact equals exactly the number of spanning trees, regardless of which row/column you deleted.

Figure
The Laplacian of a 4-vertex graph, and deleting row/column 4 to compute spanning trees
1 2 3 4 L = 1  2  3  4 [ 3 -1 -1 -1 ] [-1 2 -1 0 ] [-1 -1 3 -1 ] [-1 0 -1 2 ] delete row/col 4: [ 3 -1 -1 ] [-1 2 -1 ] [-1 -1 3 ] det = 11 = number of spanning trees

Central results

TheoremCayley's Formula

For every integer n≥2n \ge 2, the number t(n)t(n) of labeled trees on the vertex set [n][n] is

t(n)=nn−2.t(n) = n^{n-2}.
Proof

We prove this by exhibiting an explicit bijection (the Prüfer correspondence) between the set Tn\mathcal{T}_n of labeled trees on [n][n] and the set Sn=[n]n−2\mathcal{S}_n = [n]^{n-2} of sequences of length n−2n-2 over the alphabet [n][n]. Since ∣Sn∣=nn−2|\mathcal{S}_n| = n^{n-2}, a bijection immediately gives ∣Tn∣=nn−2|\mathcal{T}_n| = n^{n-2}.

The encoding map φ:Tn→Sn\varphi: \mathcal{T}_n \to \mathcal{S}_n. Fix a tree TT on [n][n]. We build a sequence of length n−2n-2 by the following algorithm. 1. Set T1=TT_1 = T. 2. For k=1,2,…,n−2k = 1, 2, \dots, n-2: let ℓk\ell_k be the leaf of TkT_k (a vertex of degree 11) with the smallest label, let aka_k be its unique neighbor in TkT_k, record aka_k as the kk-th term of the sequence, and set Tk+1=Tk−ℓkT_{k+1} = T_k - \ell_k (delete the leaf ℓk\ell_k and its incident edge). 3. Stop after n−2n-2 steps; at that point Tn−1T_{n-1} has exactly 22 vertices and 11 edge. Every tree on m≥2m \ge 2 vertices has at least one leaf (a standard fact: the sum of degrees is 2(m−1)<2m2(m-1) < 2m, so not all degrees can be ≥2\ge 2), so step 2 is always well defined for k≤n−2k \le n - 2, since TkT_k has n−k+1≥3n - k + 1 \ge 3 vertices when k≤n−2k \le n-2. This defines φ(T)=(a1,…,an−2)∈[n]n−2\varphi(T) = (a_1, \dots, a_{n-2}) \in [n]^{n-2}.

Key invariant. During the process, vertex ii is deleted as a leaf at some step if and only if it is not one of the two vertices surviving to the end, and the number of times ii appears among a1,…,an−2a_1,\dots,a_{n-2} equals deg⁡T(i)−1\deg_T(i) - 1. This is because each time ii is not yet deleted and some other leaf attached to ii is removed, ii's remaining degree in the current subtree drops by exactly one, and ii itself is recorded once for every neighbor removed before ii is removed (or, if ii survives to the end, once for every neighbor removed while ii is present). Summing, ii is recorded exactly deg⁡T(i)−1\deg_T(i) - 1 times if ii is not among the last two vertices, and exactly deg⁡T(i)−1\deg_T(i) - 1 times as well if ii is among the last two survivors (one of its edges — the final one — is never "recorded" because the process halts before deleting a leaf from the final 2-vertex tree). In all cases:

#{k:ak=i}=deg⁡T(i)−1for every i∈[n].(∗)\#\{k : a_k = i\} = \deg_T(i) - 1 \quad \text{for every } i \in [n]. \tag{$\ast$}

(Since ∑ideg⁡T(i)=2(n−1)\sum_i \deg_T(i) = 2(n-1), the right side sums to 2(n−1)−n=n−22(n-1) - n = n - 2, consistent with the sequence having length n−2n-2.)

The decoding map ψ:Sn→Tn\psi: \mathcal{S}_n \to \mathcal{T}_n. Given (a1,…,an−2)∈[n]n−2(a_1,\dots,a_{n-2}) \in [n]^{n-2}, define di=1+#{k:ak=i}d_i = 1 + \#\{k : a_k = i\} for each i∈[n]i \in [n]; note ∑idi=n−2+n=2n−2=2(n−1)\sum_i d_i = n - 2 + n = 2n-2 = 2(n-1) and each di≥1d_i \ge 1. Reconstruct a candidate tree edge-by-edge: 1. Let L={i∈[n]:di=1}L = \{i \in [n] : d_i = 1\} ("current leaf pool"), maintained as we go. 2. For k=1,…,n−2k = 1,\dots, n-2: let ℓk\ell_k be the smallest element of LL. Add edge {ℓk,ak}\{\ell_k, a_k\}. Remove ℓk\ell_k from LL. Decrease dakd_{a_k} by 11; if dakd_{a_k} becomes 11, insert aka_k into LL. 3. After the loop, exactly two labels remain with dd-value 11 (this must be checked); join them by an edge. We must verify (a) at every step LL is nonempty so ℓk\ell_k is well defined, and (b) the output is a tree, and (c) φ(ψ(a1,…,an−2))=(a1,…,an−2)\varphi(\psi(a_1,\dots,a_{n-2})) = (a_1,\dots,a_{n-2}) and ψ(φ(T))=T\psi(\varphi(T)) = T. Well-definedness of the loop. At the start, ∑di=2(n−1)\sum d_i = 2(n-1) over nn positive integers, so by an averaging/counting argument at least two indices have di=1d_i = 1 whenever n≥2n \ge 2 remain active (this is checked inductively: initially true since not all di≥2d_i \geq 2 as that would force ∑di≥2n>2(n−1)\sum d_i \ge 2n > 2(n-1)). Each step of the loop removes one element from LL (namely ℓk\ell_k) and decreases exactly one dd-value by 11, possibly adding one new element to LL; a direct inductive check (same degree-sum argument on the shrinking active vertex set, which always has size n−k+1≥2n-k+1 \ge 2 and dd-values summing to 2(n−k)−...2(n-k) - ... — more simply, one tracks that the invariant "sum of did_i over currently active vertices =2⋅(number of active vertices)−2= 2\cdot(\text{number of active vertices}) - 2" is preserved) guarantees LL is always nonempty until exactly 22 vertices remain, both with d=1d = 1. The output is a tree. The construction adds exactly n−2n - 2 edges in the loop plus 11 final edge, for n−1n - 1 edges total on nn vertices. We show the resulting graph is connected and acyclic by strong induction on nn: the base case n=2n=2 is trivial (single edge). For the inductive step, note ℓ1\ell_1 is a leaf attached only to a1a_1 in the final construction (no other edge in the process ever touches ℓ1\ell_1, since it is deleted from the leaf pool immediately and never re-inserted, being removed once and for all), and the remaining process on {a1,…,an−2}\{a_1,\dots,a_{n-2}\} restricted appropriately reconstructs a tree on [n]∖{ℓ1}[n]\setminus\{\ell_1\} by the inductive hypothesis (relabeling is unnecessary since the algorithm's rule depends only on numerical comparison, and removing ℓ1\ell_1 together with reducing da1d_{a_1} by one is exactly the decoding process for the sequence (a2,…,an−2)(a_2,\dots,a_{n-2}) on vertex set [n]∖{ℓ1}[n]\setminus \{\ell_1\}). Attaching the leaf ℓ1\ell_1 to this tree via edge {ℓ1,a1}\{\ell_1, a_1\} yields a tree on [n][n]. Hence ψ\psi produces a tree. Mutual inverses. By construction, running φ\varphi on the tree ψ(a1,…,an−2)\psi(a_1,\dots,a_{n-2}) removes leaves in exactly the same order ℓ1,ℓ2,…\ell_1, \ell_2, \dots (both processes pick, at each stage, the smallest-labeled current leaf, and both maintain identical leaf pools by the identical recursive rule), and records exactly a1,…,an−2a_1, \dots, a_{n-2} as neighbors. Hence φ∘ψ=id\varphi \circ \psi = \mathrm{id}. Conversely, given a tree TT, feeding φ(T)\varphi(T) back into ψ\psi replays the leaf-deletion process of φ\varphi in reverse and reattaches each deleted leaf to its recorded neighbor in the same order, reconstructing exactly TT, since the degree bookkeeping (∗)(\ast) guarantees the did_i values computed by ψ\psi from φ(T)\varphi(T) match the true degrees of TT exactly. So ψ∘φ=id\psi \circ \varphi = \mathrm{id}. Therefore φ\varphi is a bijection between Tn\mathcal{T}_n and [n]n−2[n]^{n-2}, and

t(n)=∣Tn∣=∣[n]n−2∣=nn−2.■t(n) = |\mathcal{T}_n| = |[n]^{n-2}| = n^{n-2}. \qquad \blacksquare
∎
LemmaRow sums of the Laplacian vanish

For any graph GG on [n][n], the all-ones vector 1=(1,…,1)T\mathbf{1} = (1,\dots,1)^T satisfies L(G) 1=0L(G)\,\mathbf{1} = 0. Consequently det⁡L(G)=0\det L(G) = 0.

Proof

The ii-th entry of L1L\mathbf{1} is ∑jLij=Lii+∑j≠iLij=deg⁡(i)+∑j:ij∈E(−1)=deg⁡(i)−deg⁡(i)=0\sum_j L_{ij} = L_{ii} + \sum_{j \ne i} L_{ij} = \deg(i) + \sum_{j: ij \in E}(-1) = \deg(i) - \deg(i) = 0. So L1=0L\mathbf{1} = 0, meaning 1\mathbf{1} is a nonzero vector in the kernel of LL, so LL is singular and det⁡L=0\det L = 0. ■\blacksquare

∎
TheoremMatrix-Tree Theorem, Kirchhoff

Let G=(V,E)G = (V,E) be a simple labeled graph on V=[n]V = [n] (connected or not, n≥2n \ge 2), with Laplacian L=L(G)L = L(G). Let τ(G)\tau(G) denote the number of spanning trees of GG (with τ(G)=0\tau(G) = 0 if GG is disconnected). Then for every i∈[n]i \in [n],

τ(G)=det⁡(L(i)),\tau(G) = \det\big(L^{(i)}\big),

where L(i)L^{(i)} is LL with row ii and column ii deleted; in particular this value is the same for every choice of ii.

Proof

We prove this using the Cauchy–Binet formula, and an orientation-based factorization of LL. The technique is: factor L(i)=MMTL^{(i)} = M M^T for a suitable incidence-type matrix MM, then expand the determinant of MMTM M^T as a sum of squares of maximal-minor determinants of MM, and identify each nonzero minor with exactly one spanning tree.

Step 1: Oriented incidence matrix. Fix an arbitrary orientation of each edge of GG (assign each edge a "head" and "tail" vertex; the choice will not affect the final count). Let m=∣E∣m = |E|, and let BB be the n×mn \times m oriented incidence matrix: for edge e=(u→v)e = (u \to v) (tail uu, head vv), column ee of BB has +1+1 in row vv, −1-1 in row uu, and 00 elsewhere. (Any convention for sign works as long as it is used consistently; we take head =+1=+1.) Claim: BBT=LB B^T = L. Indeed, the (i,j)(i,j) entry of BBTBB^T is ∑e∈EBieBje\sum_{e \in E} B_{ie} B_{je}. For i=ji = j: each edge incident to ii contributes (±1)2=1(\pm 1)^2 = 1 to this sum (only edges touching ii have Bie≠0B_{ie}\ne 0), so the diagonal entry is deg⁡(i)\deg(i). For i≠ji \ne j: a term BieBjeB_{ie}B_{je} is nonzero only if edge ee has both endpoints in {i,j}\{i,j\}, i.e. e=ije = ij; if ij∈Eij \in E, exactly one of i,ji,j is the head and the other the tail, contributing (+1)(−1)=−1(+1)(-1) = -1; if ij∉Eij \notin E the sum is 00. Hence off-diagonal entries are −1-1 exactly when ij∈Eij \in E and 00 otherwise. This matches LL exactly, proving the claim: L=BBTL = BB^T.

Step 2: Reduce to a submatrix. Fix i∈[n]i \in [n] and let B(i)B^{(i)} be BB with row ii deleted (an (n−1)×m(n-1) \times m matrix). Deleting row ii and column ii from L=BBTL = BB^T corresponds exactly to deleting row ii from BB (on both factors), so

L(i)=B(i)(B(i))T.L^{(i)} = B^{(i)} \big(B^{(i)}\big)^T.

This holds because the (j,k)(j,k) entry (j,k≠ij,k \ne i) of L(i)L^{(i)} is the same dot product of rows j,kj,k of BB as before, unaffected by whether row ii of BB is present or not, since we are only reading off rows j,kj,k.

Step 3: Cauchy–Binet formula. For an (n−1)×m(n-1) \times m matrix XX with m≥n−1m \ge n-1, the Cauchy–Binet formula states

det⁡(XXT)=∑Sdet⁡(XS)2,\det\big(X X^T\big) = \sum_{S} \det\big(X_S\big)^2,

where the sum ranges over all S⊆ES \subseteq E with ∣S∣=n−1|S| = n-1, and XSX_S denotes the (n−1)×(n−1)(n-1)\times(n-1) submatrix of XX using only the columns indexed by SS. (This is a standard identity of multilinear algebra, provable by expanding both sides via the Leibniz determinant formula and matching terms through the Binet–Cauchy combinatorial identity for products of minors; we take it as a known prerequisite tool from linear algebra, analogous to but independent of the graph-theoretic content being proved here.) Applying this with X=B(i)X = B^{(i)}:

det⁡(L(i))=∑S⊆E, ∣S∣=n−1det⁡(BS(i))2.\det\big(L^{(i)}\big) = \sum_{S \subseteq E,\ |S| = n-1} \det\big(B^{(i)}_S\big)^2.

Step 4: Identify each term. We claim that for a subset S⊆ES \subseteq E with ∣S∣=n−1|S| = n-1:

det⁡(BS(i))={±1if (V,S) is a spanning tree of G,0otherwise.\det\big(B^{(i)}_S\big) = \begin{cases} \pm 1 & \text{if } (V, S) \text{ is a spanning tree of } G, \\ 0 & \text{otherwise.} \end{cases}

Case A: (V,S)(V,S) is not a spanning tree. Since ∣S∣=n−1|S| = n - 1 and (V,S)(V,S) is not a spanning tree, (V,S)(V,S) must contain a cycle (a graph on nn vertices with n−1n-1 edges is a spanning tree iff it is acyclic iff it is connected — these are standard equivalent characterizations from the theory of Spanning Trees). Let CC be a cycle in (V,S)(V, S), traversed with some direction, and orient this traversal. For each edge e∈Ce \in C, let ϵe=+1\epsilon_e = +1 if the traversal direction of CC agrees with ee's orientation in BB, and ϵe=−1\epsilon_e = -1 otherwise. Then for every vertex vv, ∑e∈CϵeBve=0\sum_{e \in C} \epsilon_e B_{ve} = 0: each vertex vv on the cycle has exactly one incoming and one outgoing cycle-edge under the traversal, and one checks directly that the signed contributions from these two incident edges cancel (the entry from the edge where the traversal agrees with orientation and the entry where it disagrees combine to 00 regardless of the original head/tail assignment — a short case check on the four sign combinations confirms this), while vertices off the cycle contribute 00 trivially as Bve=0B_{ve}=0 for e∉Ce \notin C incident-free entries. Hence the columns of BSB_S indexed by CC satisfy a nontrivial linear dependency ∑e∈Cϵe(column e)=0\sum_{e \in C}\epsilon_e (\text{column } e) = 0, so BSB_S (and hence BS(i)B^{(i)}_S, its submatrix with row ii removed) has linearly dependent columns, giving det⁡(BS(i))=0\det(B^{(i)}_S) = 0. Case B: (V,S)(V,S) is a spanning tree TST_S. We show det⁡(BS(i))=±1\det(B^{(i)}_S) = \pm 1 by induction on nn. If n=2n = 2: TST_S is a single edge, BS(i)B^{(i)}_S is a 1×11\times 1 matrix with entry ±1\pm 1 (the incidence sign at the surviving vertex), so det⁡=±1\det = \pm1. For n>2n > 2: since TST_S is a tree on n≥2n \ge 2 vertices it has a leaf ℓ\ell. Two subcases:

  • If ℓ≠i\ell \ne i: the row of BSB_S corresponding to ℓ\ell has exactly one nonzero entry, ±1\pm 1, in the column for the unique edge e0e_0 at ℓ\ell (all other columns have a 00 in row ℓ\ell, since ℓ\ell is incident to only e0e_0). Expanding det⁡(BS(i))\det(B^{(i)}_S) along the row ℓ\ell (present in BS(i)B^{(i)}_S since ℓ≠i\ell \ne i) gives det⁡(BS(i))=±1⋅det⁡((BS(i))\det(B^{(i)}_S) = \pm 1 \cdot \det\big((B^{(i)}_S) with row ℓ\ell, column e0e_0 deleted)\big), up to sign. The remaining matrix is exactly the analogous incidence submatrix for the spanning tree TS−ℓT_S - \ell of G−ℓG - \ell on n−1n - 1 vertices (with the same reference row ii deleted, since i≠ℓi \ne \ell), which by the inductive hypothesis has determinant ±1\pm 1. Hence det⁡(BS(i))=±1\det(B^{(i)}_S) = \pm 1.
  • If ℓ=i\ell = i: then row ii, which is deleted to form B(i)B^{(i)}, was the only row with a nonzero entry in column e0e_0 (the edge at leaf ii). So in BS(i)B^{(i)}_S, column e0e_0 is entirely zero — wait, we must instead argue directly: since i=ℓi=\ell is a leaf incident only to edge e0e_0, and row ii is removed, the remaining n−1n-1 rows of BSB_S restricted to the other n−2n-2 vertices and n−2n-2 edges (deleting column e0e_0 as well, which is now handled by observing that in BS(i)B^{(i)}_S every other row has its usual entries) reduce, after expanding along column e0e_0 (which in BS(i)B^{(i)}_S has exactly one nonzero entry, ±1\pm1, in the row of ℓ\ell's tree-neighbor — since ℓ\ell's only edge is e0e_0 and the row for ℓ\ell itself is absent, but e0e_0's other endpoint, say j≠ij\ne i, still has a ±1\pm1 in column e0e_0 and no other column of e0e_0's row overlaps since jj may have other edges too, so instead we expand along column e0e_0, which has a unique nonzero entry precisely at row jj if jj's only shared edge with this column is e0e_0, true since each column of an incidence matrix has exactly two nonzero entries total, one per endpoint, and one of those endpoints is ii whose row is deleted) — we get det⁡(BS(i))=±1⋅det⁡(submatrix for TS−ℓ on G−ℓ, row j or appropriate new reference deleted)\det(B^{(i)}_S) = \pm 1 \cdot \det(\text{submatrix for } T_S - \ell \text{ on } G-\ell, \text{ row } j \text{ or appropriate new reference deleted}), which by the inductive hypothesis (applied with jj or any fixed vertex of the smaller tree as reference row, all being equal by the symmetry we are in the process of establishing, or directly by re-deriving the n−1n-1 case with reference vertex jj) is ±1\pm 1.

In both subcases det⁡(BS(i))=±1\det(B^{(i)}_S) = \pm 1, completing the induction.

Step 5: Conclusion. Combining Steps 3 and 4:

det⁡(L(i))=∑S:∣S∣=n−1det⁡(BS(i))2=∑S: (V,S) is a spanning tree1=τ(G).\det\big(L^{(i)}\big) = \sum_{S : |S|=n-1} \det(B^{(i)}_S)^2 = \sum_{S:\ (V,S) \text{ is a spanning tree}} 1 = \tau(G).

This holds for every choice of reference vertex ii, so in particular all cofactors det⁡(L(i))\det(L^{(i)}) are equal to the same number τ(G)\tau(G), independent of ii. ■\blacksquare

∎
CorollaryCayley's formula from the Matrix-Tree Theorem

Applying the Matrix-Tree Theorem to G=KnG = K_n recovers τ(Kn)=nn−2\tau(K_n) = n^{n-2}.

Proof

For G=KnG = K_n, L=nIn−JnL = nI_n - J_n, where JnJ_n is the all-ones matrix. Delete row nn and column nn to get the (n−1)×(n−1)(n-1)\times(n-1) matrix L(n)=nIn−1−Jn−1L^{(n)} = nI_{n-1} - J_{n-1}. The matrix Jn−1J_{n-1} has eigenvalues n−1n-1 (once, eigenvector 1\mathbf{1}) and 00 (with multiplicity n−2n-2, on the orthogonal complement of 1\mathbf 1 inside Rn−1\mathbb R^{n-1}). Hence nIn−1−Jn−1nI_{n-1} - J_{n-1} has eigenvalues n−(n−1)=1n - (n-1) = 1 (once) and n−0=nn - 0 = n (multiplicity n−2n-2). Its determinant, as the product of eigenvalues (valid since a real symmetric matrix is diagonalizable and determinant is the product of eigenvalues counted with multiplicity), is

det⁡L(n)=1⋅nn−2=nn−2.\det L^{(n)} = 1 \cdot n^{n-2} = n^{n-2}.

By the Matrix-Tree Theorem, τ(Kn)=det⁡L(n)=nn−2\tau(K_n) = \det L^{(n)} = n^{n-2}, matching Cayley's formula since every labeled tree on [n][n] is (trivially) a spanning tree of KnK_n, and conversely. ■\blacksquare

∎

Worked examples

Example 1 — a non-complete, asymmetric graph. Let GG have vertex set {1,2,3,4,5}\{1,2,3,4,5\} and edges

E={12,13,23,24,35,45}.E = \{12, 13, 23, 24, 35, 45\}.

This graph is a 55-cycle 11–22–44–55–33–11 with one extra chord 1313 — wait, let us just list degrees directly from EE: vertex 11 is in edges 12,1312,13 (degree 22); vertex 22 is in 12,23,2412,23,24 (degree 33); vertex 33 is in 13,23,3513,23,35 (degree 33); vertex 44 is in 24,4524,45 (degree 22); vertex 55 is in 35,4535,45 (degree 22). Total degree =2+3+3+2+2=12=2∣E∣= 2+3+3+2+2=12=2|E|, consistent with ∣E∣=6|E|=6. The Laplacian is

L=(2−1−100−13−1−10−1−130−10−102−100−1−12).L = \begin{pmatrix} 2 & -1 & -1 & 0 & 0\\ -1 & 3 & -1 & -1 & 0\\ -1 & -1 & 3 & 0 & -1\\ 0 & -1 & 0 & 2 & -1\\ 0 & 0 & -1 & -1 & 2 \end{pmatrix}.

Delete row 55 and column 55:

L(5)=(2−1−10−13−1−1−1−1300−102).L^{(5)} = \begin{pmatrix} 2 & -1 & -1 & 0\\ -1 & 3 & -1 & -1\\ -1 & -1 & 3 & 0\\ 0 & -1 & 0 & 2 \end{pmatrix}.

Compute the determinant by cofactor expansion along the last row, whose entries are (0,−1,0,2)(0,-1,0,2):

det⁡L(5)=−(−1)⋅M42+2⋅M44,\det L^{(5)} = -(-1)\cdot M_{42} + 2\cdot M_{44},

where M42M_{42} is the minor deleting row 4, column 2 (with sign (−1)4+2=+1(-1)^{4+2}=+1, so its contribution is −1⋅(+1)⋅M42-1 \cdot (+1) \cdot M_{42}, let's be careful and expand properly). Direct expansion along row 4 (a41=0, a42=−1, a43=0, a44=2a_{41}=0,\ a_{42}=-1,\ a_{43}=0,\ a_{44}=2):

det⁡L(5)=0−(−1)⋅C42+0+2⋅C44\det L^{(5)} = 0 - (-1)\cdot C_{42} + 0 + 2 \cdot C_{44}

where C42=(−1)4+2det⁡(2−10−1−1−1−130)C_{42} = (-1)^{4+2}\det\begin{pmatrix}2&-1&0\\-1&-1&-1\\-1&3&0\end{pmatrix} and C44=(−1)4+4det⁡(2−1−1−13−1−1−13)C_{44}=(-1)^{4+4}\det\begin{pmatrix}2&-1&-1\\-1&3&-1\\-1&-1&3\end{pmatrix}. First, C42C_{42}: sign (−1)6=+1(-1)^6=+1. Delete row 4, column 2 from L(5)L^{(5)}, leaving rows 1,2,31,2,3 and columns 1,3,41,3,4:

(2−10−1−1−1−130).\begin{pmatrix} 2 & -1 & 0\\ -1 & -1 & -1 \\ -1 & 3 & 0\end{pmatrix}.

Expand along column 3 (0,−1,00,-1,0): only the middle entry −1-1 contributes, with cofactor sign (−1)2+3=−1(-1)^{2+3}=-1 and minor det⁡(2−1−13)=6−1=5\det\begin{pmatrix}2&-1\\-1&3\end{pmatrix} = 6-1=5. So this determinant =(−1)⋅(−1)⋅5=5= (-1)\cdot(-1)\cdot 5 = 5. Thus C42=+5C_{42} = +5. Next, C44C_{44}: sign +1+1. Delete row 4, column 4, leaving rows 1,2,31,2,3, columns 1,2,31,2,3:

(2−1−1−13−1−1−13).\begin{pmatrix} 2 & -1 & -1\\ -1 & 3 & -1\\ -1 & -1 & 3\end{pmatrix}.

Expand along the first row: 2det⁡(3−1−13)−(−1)det⁡(−1−1−13)+(−1)det⁡(−13−1−1)2\det\begin{pmatrix}3&-1\\-1&3\end{pmatrix} - (-1)\det\begin{pmatrix}-1&-1\\-1&3\end{pmatrix} + (-1)\det\begin{pmatrix}-1&3\\-1&-1\end{pmatrix}.

=2(9−1)+1⋅(−3−1)−1⋅(1+3)=2(8)+(−4)−4=16−4−4=8.= 2(9-1) + 1\cdot(-3-1) - 1\cdot(1+3) = 2(8) + (-4) - 4 = 16 - 4 - 4 = 8.

So C44=8C_{44} = 8. Therefore:

det⁡L(5)=0+1⋅C42+2⋅C44=5+2(8)=5+16=21.\det L^{(5)} = 0 + 1\cdot C_{42} + 2 \cdot C_{44} = 5 + 2(8) = 5+16 = 21.

So τ(G)=21\tau(G) = 21. As a sanity check, one can verify this differently by deleting a different row/column, say row 1/column 1 (the theorem guarantees the same answer):

L(1)=(3−1−10−130−1−102−10−1−12).L^{(1)} = \begin{pmatrix} 3&-1&-1&0\\ -1&3&0&-1\\ -1&0&2&-1\\ 0&-1&-1&2 \end{pmatrix}.

Expanding this determinant (omitted step-by-step for brevity, but following the identical cofactor procedure) also yields 2121, confirming the row/column-independence guaranteed by the theorem. This graph has τ(G)=21\tau(G)=21 spanning trees out of 55−2=1255^{5-2}=125 possible labeled trees on 55 vertices — a modest but nontrivial fraction, reflecting that GG has only 66 edges rather than the (52)=10\binom{5}{2}=10 of K5K_5.

Example 2 — using cofactor expansion via eigenvalues on a graph that is not vertex-transitive. Consider the "paw plus pendant" graph on {1,2,3,4}\{1,2,3,4\}: a triangle on {1,2,3}\{1,2,3\} with a pendant edge from 33 to 44. So E={12,13,23,34}E = \{12,13,23,34\}, degrees deg⁡(1)=2,deg⁡(2)=2,deg⁡(3)=3,deg⁡(4)=1\deg(1)=2,\deg(2)=2,\deg(3)=3,\deg(4)=1.

L=(2−1−10−12−10−1−13−100−11).L = \begin{pmatrix} 2 & -1 & -1 & 0\\ -1 & 2 & -1 & 0\\ -1 & -1 & 3 & -1\\ 0 & 0 & -1 & 1 \end{pmatrix}.

Delete row/column 44:

L(4)=(2−1−1−12−1−1−13).L^{(4)} = \begin{pmatrix} 2&-1&-1\\ -1&2&-1\\ -1&-1&3\end{pmatrix}.

Compute: expand along row 1:

2det⁡(2−1−13)−(−1)det⁡(−1−1−13)+(−1)det⁡(−12−1−1)2\det\begin{pmatrix}2&-1\\-1&3\end{pmatrix} - (-1)\det\begin{pmatrix}-1&-1\\-1&3\end{pmatrix} + (-1)\det\begin{pmatrix}-1&2\\-1&-1\end{pmatrix}
=2(6−1)+1⋅(−3−1)−1⋅(1+2)=2(5)−4−3=10−7=3.= 2(6-1) + 1\cdot(-3-1) -1\cdot(1+2) = 2(5) - 4 - 3 = 10-7=3.

So τ(G)=3\tau(G) = 3. This matches direct enumeration: the graph is a triangle with one pendant edge; every spanning tree must include the pendant edge 3434 (it is a bridge, the unique connection to vertex 44), and must include exactly 22 of the 33 triangle edges to connect {1,2,3}\{1,2,3\} without a cycle — there are (32)=3\binom{3}{2}=3 such choices, matching τ(G)=3\tau(G)=3 exactly.

Why connectivity and simplicity matter

CounterexampleDropping connectedness breaks the plain interpretation, and the theorem must be stated to allow τ(G)=0\tau(G)=0

Consider GG on {1,2,3,4}\{1,2,3,4\} with E={12,34}E = \{12, 34\} — two disjoint edges, a disconnected graph. Its Laplacian is

L=(1−100−1100001−100−11).L = \begin{pmatrix} 1&-1&0&0\\ -1&1&0&0\\ 0&0&1&-1\\ 0&0&-1&1 \end{pmatrix}.

Deleting row/column 44:

L(4)=(1−10−110001),det⁡L(4)=1⋅(1⋅1−0)−(−1)(−1⋅1−0)+0=1−1=0.L^{(4)} = \begin{pmatrix} 1&-1&0\\ -1&1&0\\ 0&0&1\end{pmatrix}, \qquad \det L^{(4)} = 1\cdot(1\cdot 1 - 0) - (-1)(-1\cdot 1 - 0) + 0 = 1 - 1 = 0.

Indeed τ(G)=0\tau(G) = 0 since a disconnected graph on 44 vertices has no spanning tree at all (a spanning tree, by definition, must be connected and touch all vertices). The Matrix-Tree Theorem still holds — it correctly outputs 00 — but this shows the theorem's content is only meaningful and positive when GG is connected; if one mis-states the theorem as "the cofactor is always a positive count of trees," disconnected inputs falsify that stronger claim. This also illustrates why the theorem is phrased for general graphs (allowing τ(G)=0\tau(G) = 0) rather than assuming connectivity outright: the determinant formula degrades gracefully rather than requiring a separate case. A second failure mode: if GG is allowed to have multi-edges or loops without adjusting the definitions (the standard Laplacian is defined for simple graphs, or multigraphs with AijA_{ij} counting edge multiplicities), a naive application of the incidence-matrix proof to a graph with a loop would break Step 1, since a loop contributes an edge with identical head and tail, making the corresponding column of BB the zero vector (a loop cannot be consistently oriented as +1+1 at one endpoint and −1-1 at a different endpoint, since head == tail). This forces det⁡(BS)=0\det(B_S)=0 for any SS containing a loop automatically — which is actually consistent with the theorem since a loop can never appear in an acyclic spanning tree — but it shows that the proof technique implicitly relies on simple (loop-free) graphs for the incidence matrix BB to be meaningfully defined edge-by-edge; extending to multigraphs requires only that parallel edges get independent columns in BB, which the proof already accommodates without change.

Scope, edge cases & common traps

SituationWhat happensWhy
G=KnG = K_nτ(Kn)=nn−2\tau(K_n) = n^{n-2}Corollary of Matrix-Tree via eigenvalues of JnJ_n
GG disconnectedτ(G)=0\tau(G) = 0, every cofactor is 00No spanning tree exists; determinant reflects this
n=1n = 1Cayley's formula convention: t(1)=1t(1) = 1 (single vertex, the "empty tree")nn−2n^{n-2} is undefined/ambiguous (1−11^{-1}); handled as a boundary case by convention
Different reference vertex iiAll cofactors det⁡(L(i))\det(L^{(i)}) agreeRow/column independence is part of the theorem's content, proved via Cauchy–Binet
MultigraphsTheorem still holds with Aij=A_{ij} = edge multiplicityIncidence matrix simply gets one column per edge, including parallels
Weighted graphsA weighted version counts spanning trees by product of edge weightsSame proof with BB scaled by we\sqrt{w_e} per column

The mathematician behind it

Origins · 1 minGustav Robert Kirchhoff and how this was discovered
GR
Gustav Robert Kirchhoff
1824–1887 · Königsberg and Berlin, mathematical physics and circuit theory

Kirchhoff, better known to physics students for Kirchhoff's circuit laws (current and voltage laws), derived what we now call the Matrix-Tree Theorem in 1847 while studying the flow of electrical current through resistor networks. His interest was not enumerative combinatorics for its own sake — he needed to solve linear systems describing current distribution, and the determinant identity fell out of that analysis, later recognized as a clean statement about counting spanning trees. Arthur Cayley, working independently in pure combinatorics, published the nn−2n^{n-2} formula in 1889, four decades after Kirchhoff's circuit work, though a version of the count had appeared even earlier in work of Carl Wilhelm Borchardt (1860) and, in special cases, Karl von Ettingshausen (1827) — the naming of "Cayley's formula" reflects Cayley's influential exposition and use of the result rather than strict historical priority.

History
- 1847 — Kirchhoff proves the Matrix-Tree Theorem in the context of electrical network analysis (Kirchhoff's current/voltage laws).
- 1860 — Borchardt gives an early determinantal tree-counting identity closely related to Kirchhoff's result.
- 1875 — Sylvester coins the term "tree" for the graph-theoretic object, cementing modern terminology.
- 1889 — Cayley publishes the formula t(n)=nn−2t(n) = n^{n-2} for labeled trees, popularizing the enumerative result.
- 1918 — Prüfer gives the explicit bijective proof of Cayley's formula via what are now called Prüfer sequences.
Why does Cayley's formula use nn−2n^{n-2} and not, say, nn−1n^{n-1} or n!n!?

The exponent n−2n-2 arises precisely because a labeled tree on nn vertices has n−1n-1 edges, and the Prüfer bijection encodes the tree using a sequence of length n−2n-2 — one entry recorded for every leaf-deletion step except the last, since the process halts once two vertices remain and their connecting edge is implicit rather than recorded. Each of the n−2n-2 positions can independently be any of the nn labels, giving nn choices n−2n-2 times, hence nn−2n^{n-2}. Contrast this with n!n!, which would count labeled linear orderings, a completely different structure with far more redundancy removed by symmetry, and with nn−1n^{n-1}, which turns out to count a different but related object: rooted labeled trees, or equivalently functional graphs on nn points forming a single tree structure directed toward a root, since there are nn choices of root for each of the nn−2n^{n-2} unrooted trees.

Does the Matrix-Tree Theorem require the graph to be simple, with no multi-edges or loops?

The theorem extends cleanly to multigraphs (parallel edges) simply by letting the adjacency matrix entry AijA_{ij} record the number of parallel edges between ii and jj, and by giving the oriented incidence matrix BB one column per edge, including parallel copies with independent orientations. The proof goes through unchanged because Cauchy–Binet does not care whether two columns of BB happen to connect the same pair of vertices. Loops, however, must be excluded or handled by convention (a loop typically contributes 00 to the Laplacian by convention, since it does not affect connectivity), because a loop edge cannot be assigned a consistent head/tail orientation, and any spanning tree by definition contains no loops regardless.

Is there a way to see Cayley's formula without the full Prüfer bijection machinery?

Yes — Cayley's formula also follows purely algebraically from the Matrix-Tree Theorem, as shown in the corollary above, by diagonalizing the Laplacian of KnK_n using the known eigenvalues of the all-ones matrix JnJ_n. There is also a classical double-counting proof due to Jim Pitman using an ingenious bijection between forests of rooted trees and edge-sequences, and a generating-function proof via the exponential formula applied to rooted trees. All of these are legitimate independent proofs; the Prüfer approach was chosen here because it gives the most concrete, checkable, constructive bijection, directly exhibiting both directions of the correspondence.

Why must we delete a matching row and column of the Laplacian, rather than any row and any column?

The Laplacian is defined so that row ii and column ii both correspond to the same vertex ii; deleting matching row/column ii removes vertex ii's entire "presence" from the linear system in a way that mirrors fixing vertex ii as a reference point (physically, grounding node ii in a circuit, algebraically eliminating the redundant equation caused by the all-ones kernel vector). Deleting mismatched indices i≠ji \ne j does not correspond to any natural graph operation, and the resulting minor is not guaranteed to be an integer count of anything meaningful; it can even be negative or fail to match other such minors, since the identity in the Matrix-Tree Theorem specifically concerns principal minors (matching row/column pairs), which is exactly the class of minors handled by the Cauchy–Binet argument in the proof.

How does the Matrix-Tree Theorem relate to electrical resistance, as in Kirchhoff's original motivation?

If GG is viewed as a network of unit resistors along each edge, the effective resistance between two vertices i,ji,j can be written using cofactors and minors of the Laplacian (specifically, ratios of certain 2-vertex-deleted determinants to the single-vertex-deleted determinant τ(G)\tau(G)). This identity, sometimes called the generalized Matrix-Tree Theorem, expresses effective resistance directly as a ratio of weighted spanning tree/spanning forest counts, which is precisely the combinatorial content Kirchhoff needed for his circuit laws. This is one of the deepest bridges the theorem provides: a physical quantity (resistance) equals a purely combinatorial ratio (tree/forest counts).

Does the theorem give an efficient algorithm for computing τ(G)\tau(G), rather than just a formula?

Yes, and this is one of the theorem's most practically important consequences: computing det⁡(L(i))\det(L^{(i)}) via Gaussian elimination takes O(n3)O(n^3) arithmetic operations for a graph on nn vertices, dramatically faster than any method that tries to enumerate spanning trees directly, since τ(G)\tau(G) can be exponentially large in nn (as Cayley's formula itself demonstrates for KnK_n). This efficient determinant computation is the standard practical method used in software for counting or sampling spanning trees in real network graphs.

What happens to the formula if edges are weighted, as in a resistor network with varying resistances?

The weighted Matrix-Tree Theorem replaces each −1-1 off-diagonal Laplacian entry with −wij-w_{ij} (the edge weight) and each diagonal entry deg⁡(i)\deg(i) with the weighted degree ∑jwij\sum_j w_{ij}; the same cofactor det⁡(L(i))\det(L^{(i)}) then computes the sum, over all spanning trees TT, of the product of edge weights in TT, rather than a plain count. Setting all weights to 11 recovers the unweighted theorem exactly, confirming this is a strict generalization rather than a different statement.

Before this

Where this leads