Trees

Study Sheet

Trees

The many equivalent definitions of a tree, spanning trees, and counting labeled trees

What Makes a Tree

Concept
Tree: four faces of one idea

A graph TT on nn vertices is a tree if it is connected and has no cycles. For such a graph, these are all equivalent: (1) connected and acyclic; (2) connected with exactly n−1n - 1 edges; (3) acyclic with exactly n−1n - 1 edges; (4) any two vertices are joined by a unique path. A tree is also exactly a connected graph in which every edge is a bridge (removing it disconnects the graph), and exactly an acyclic graph in which adding any new edge creates exactly one cycle.

A tree sits exactly on the boundary between "connected" and "acyclic": each property forces the other once you fix the vertex count, which Why It Works proves. The intuition is counting: reaching nn vertices from one takes at least n−1n - 1 edges, so a connected graph with exactly n−1n - 1 edges has no edge to spare for a cycle, and an acyclic graph with n−1n - 1 edges has no vertex left unreached. Uniqueness of paths is the same fact stated differently — a second path between two vertices would close a cycle with the first. A single vertex with no edges counts as a (trivial) tree.

Example
Confirming a tree five ways
123456
The tree T1T_1: six vertices, five edges, one path between any two.

Let T1T_1 have vertices {1,…,6}\{1, \ldots, 6\} and edges 12,13,24,25,3612, 13, 24, 25, 36. It has n=6n = 6 vertices and 5=n−15 = n - 1 edges. Tracing from vertex 11 reaches 22 and 33 directly, then 4,54, 5 through 22 and 66 through 33 — all six vertices, so T1T_1 is connected. With 55 edges already forced to be exactly enough to connect 66 vertices, no edge is free to close a cycle; indeed the unique path from 44 to 66 is 4-2-1-3-64\text{-}2\text{-}1\text{-}3\text{-}6, with no alternative route. So T1T_1 is a tree.

Example
One new edge, exactly one cycle
123456
Adding edge 4–5 closes exactly one cycle, 2-4-5.

Add the edge 4545 to T1T_1, joining two vertices that were not adjacent. Now there are 66 edges on 66 vertices — one too many to stay acyclic — and indeed 2,4,52, 4, 5 now form a cycle: 2-42\text{-}4, 4-54\text{-}5, 5-25\text{-}2 are all edges. Every degree outside {4,5}\{4, 5\} is unchanged; 44 and 55 each gain the new edge, going from degree 11 to degree 22. This is the last equivalence above in action: in a tree, joining any two non-adjacent vertices creates exactly one cycle, running along the old tree-path between them.

Example
A graph with exactly n−1n - 1 edges that is not a tree
1234567
Six edges on seven vertices, but two disconnected pieces — not a tree.

On vertices {1,…,7}\{1, \ldots, 7\}, take edges 12,23,1312, 23, 13 (a triangle) together with 45,56,6745, 56, 67 (a path). That is 6=7−16 = 7 - 1 edges — the right count for a tree — but vertex 11 can never reach vertex 44: the graph splits into two pieces. So having n−1n - 1 edges is not enough on its own; this graph is acyclic nowhere near enough (it has the triangle) and disconnected, failing BOTH halves of the equivalence at once. A real test must check connectivity and the edge count together (or acyclicity and the edge count together).

Side note
Where it goes wrong

The smallest trap: nn vertices and n−1n - 1 edges, checked only by counting. On {1,2,3,4}\{1, 2, 3, 4\}, take the triangle 12,23,1312, 23, 13 and leave vertex 44 untouched — 3=4−13 = 4 - 1 edges, yet 44 is isolated and the triangle is a cycle. The count alone proves nothing; it is a necessary companion to connectedness (or to acyclicity), never a substitute for it.

Try it
Try it: does the count decide it?

A connected graph has 1010 vertices and 99 edges. Must it be a tree?

Show the answer

Yes. Connected with exactly n−1=9n - 1 = 9 edges is one of the four equivalent conditions, so acyclicity (and everything else in the list) comes for free — no further check is needed. The answer is **yes, it must be a tree**.

Leaves and Edge Counts

Concept
The handshake for trees, and two leaves

A tree TT with n≥2n \ge 2 vertices has n−1n - 1 edges, so by the handshake lemma ∑vdeg⁡(v)=2(n−1)\sum_v \deg(v) = 2(n - 1). TT also has at least two leaves (vertices of degree 11): if only ℓ≤1\ell \le 1 vertices had degree 11 and the rest had degree ≥2\ge 2, the sum would be at least 2n−ℓ≥2n−1>2n−2=2(n−1)2n - \ell \ge 2n - 1 > 2n - 2 = 2(n - 1), a contradiction.

This is the same n−1n - 1 from What Makes a Tree, read through the handshake lemma instead of through connectivity. The two-leaves fact is what makes induction on trees possible at all: strip off a leaf and its one edge, and n−1n - 1 vertices with n−2n - 2 edges remain a tree (still connected, no new cycle could appear by removing an edge), ready for the same argument again. Cayley's Formula below builds an entire counting bijection on exactly this move.

Example
Counting leaves in a bigger tree
1234567
The tree T2T_2: four leaves, 3,4,6,73,4,6,7, two more than the minimum.

Let T2T_2 have vertices {1,…,7}\{1, \ldots, 7\} and edges 12,23,24,15,56,5712, 23, 24, 15, 56, 57. That is 6=7−16 = 7 - 1 edges. Degrees: deg⁡(1)=2\deg(1) = 2, deg⁡(2)=3\deg(2) = 3, deg⁡(5)=3\deg(5) = 3, and deg⁡(3)=deg⁡(4)=deg⁡(6)=deg⁡(7)=1\deg(3) = \deg(4) = \deg(6) = \deg(7) = 1. The sum is 2+3+3+1+1+1+1=12=2(7−1)2 + 3 + 3 + 1 + 1 + 1 + 1 = 12 = 2(7 - 1), confirming the handshake count, and T2T_2 has four leaves, 3,4,6,73, 4, 6, 7 — more than the minimum of two, which the lemma only guarantees as a floor.

Example
From leaves to a vertex count

A tree has 1010 leaves, and every one of its other vertices has degree exactly 33. How many vertices does it have? Let kk be the number of degree-33 vertices, so n=10+kn = 10 + k and the number of edges is n−1=9+kn - 1 = 9 + k. The handshake lemma gives 2(9+k)=10⋅1+k⋅32(9 + k) = 10\cdot1 + k\cdot3, i.e. 18+2k=10+3k18 + 2k = 10 + 3k, so k=8k = 8 and n=18n = \mathbf{18}. Check: 1818 vertices give 1717 edges and degree sum 3434; directly, 10(1)+8(3)=10+24=3410(1) + 8(3) = 10 + 24 = 34 as well.

Example
Realizing a degree sequence
abcdef
A tree realizing degree sequence (3,2,2,1,1,1)(3,2,2,1,1,1).

Is (3,2,2,1,1,1)(3, 2, 2, 1, 1, 1) the degree sequence of some tree on 66 vertices? Its sum is 3+2+2+1+1+1=10=2(6−1)3 + 2 + 2 + 1 + 1 + 1 = 10 = 2(6 - 1), so the handshake count is right, and every value is at least 11. Build one: attach two leaves d,ed, e to a hub aa (giving aa degree 22 so far), then chain a-b-c-fa\text{-}b\text{-}c\text{-}f through degree-22 vertices b,cb, c to a last leaf ff, and finish with a-ba\text{-}b to bring aa to degree 33. The edges are da,ea,ab,bc,cfda, ea, ab, bc, cf — 5=6−15 = 6 - 1 of them — with degrees deg⁡(a)=3\deg(a) = 3, deg⁡(b)=deg⁡(c)=2\deg(b) = \deg(c) = 2, deg⁡(d)=deg⁡(e)=deg⁡(f)=1\deg(d) = \deg(e) = \deg(f) = 1, matching the sequence exactly.

Side note
Where it goes wrong

Matching the handshake sum is not enough either — every degree must also be at least 11. On 55 vertices, (0,3,3,1,1)(0, 3, 3, 1, 1) sums to 8=2(5−1)8 = 2(5 - 1), but a degree-00 vertex is isolated, and an isolated vertex can never belong to a connected graph. No tree has this degree sequence, sum notwithstanding.

Try it
Try it: solving for a repeated degree

A tree has 88 vertices; 55 of them are leaves, and the remaining 33 all share some degree d>1d > 1. Find dd.

Show the answer

With n=8n = 8 there are 77 edges, so the degree sum is 1414. The leaves contribute 55, leaving 3d=14−5=93d = 14 - 5 = 9, so d=3d = \mathbf{3}.

Spanning Trees

Concept
Spanning trees and circuit rank

A spanning tree of a connected graph GG is a subgraph that is a tree and includes every vertex of GG. Every connected graph has one: while some edge lies on a cycle, delete it (connectivity survives, since a cycle edge is never a bridge) and repeat; this must stop, and it stops exactly at a tree. If GG has nn vertices and mm edges, any spanning tree uses n−1n - 1 of them, leaving m−(n−1)m - (n - 1) edges unused — the graph's circuit rank, the fewest edges whose removal leaves a tree.

This is What Makes a Tree run in reverse: instead of checking whether a given graph is a tree, we strip a larger connected graph down to one. The bridges from that section are exactly the edges every spanning tree is forced to keep; the circuit rank counts the "redundant" links a network can lose and stay connected. The next two sections ask how many different spanning trees a graph has, first by hand, then by a formula.

Example
Trimming a graph down to a tree
1234
Dashed edges removed from G3G_3; the bold path is the spanning tree left behind.

Let G3G_3 have vertices {1,2,3,4}\{1, 2, 3, 4\} and edges 12,23,34,41,1312, 23, 34, 41, 13 — a 44-cycle with one diagonal, 55 edges on 44 vertices, so its circuit rank is 5−3=25 - 3 = 2. Edge 1313 lies on the triangle 1-2-31\text{-}2\text{-}3, so remove it; edge 4141 now lies on the remaining cycle 1-2-3-4-11\text{-}2\text{-}3\text{-}4\text{-}1, so remove it too. What is left, 12,23,3412, 23, 34, is connected (it is the path 1-2-3-41\text{-}2\text{-}3\text{-}4) and has 3=4−13 = 4 - 1 edges: a spanning tree, reached by removing exactly the circuit rank's 22 edges.

Example
Counting every spanning tree of G3G_3

How many different spanning trees does G3G_3 (above) have? Any spanning tree uses 33 of its 55 edges. Split on the diagonal 1313: if a tree uses 1313, it still needs to reach 22 (via 1212 or 2323) and 44 (via 3434 or 4141) — 2×2=42 \times 2 = 4 choices, all acyclic since each just attaches a pendant to edge 1313. If a tree avoids 1313, it must use 33 of the 44 remaining cycle edges 12,23,34,4112, 23, 34, 41; removing any one of the four from that 44-cycle leaves a spanning path, giving 44 more trees. In total G3G_3 has 4+4=84 + 4 = \mathbf{8} spanning trees.

Side note
Where it goes wrong
123456
Two disjoint triangles: no spanning tree, only a spanning forest.

A disconnected graph has no spanning tree at all — not one with fewer edges, but none. Two disjoint triangles on {1,2,3}\{1,2,3\} and {4,5,6}\{4,5,6\} have no edge between the pieces, so no single tree can reach all six vertices; the best any subgraph can do is a spanning forest, one tree per component (here, 6−2=46 - 2 = 4 edges total, two trees). "Spanning tree" always presumes a connected starting graph.

Try it
Try it: circuit rank

A connected graph has 1212 vertices and 1515 edges. At minimum, how many edges must be removed to leave a spanning tree?

Show the answer

A spanning tree uses 12−1=1112 - 1 = 11 edges, so the circuit rank is 15−11=415 - 11 = \mathbf{4}: exactly four edges must go, one from each independent cycle.

Cayley's Formula and Prufer Codes

Concept
Cayley's Formula and the Prufer code

The number of labeled trees on vertex set {1,…,n}\{1, \ldots, n\} (equivalently, the number of spanning trees of KnK_n) is nn−2n^{n-2} for n≥2n \ge 2 — Cayleys Formula. The Prufer code proves it by a direct bijection: repeatedly delete the lowest-labeled leaf and record its neighbor, until 22 vertices remain; this produces a sequence in {1,…,n}n−2\{1, \ldots, n\}^{n-2}, and every such sequence comes from exactly one tree.

Leaves and Edge Counts guaranteed a leaf exists at every stage, which is what makes the encoding process always run to completion. Because the lowest-labeled leaf is a well-defined choice at each step, encoding is deterministic, and reversing the same rule (Why It Works makes this precise) decodes any sequence back to the one tree it came from. A bijection between trees and sequences turns "count the trees" into "count the sequences," which is just nn−2n^{n-2} since each of the n−2n-2 slots is an independent choice from nn labels.

Example
Encoding a path

Find the Prufer code of the path 1-2-3-4-51\text{-}2\text{-}3\text{-}4\text{-}5. The leaves are 11 and 55; the lower one, 11, has neighbor 22, so record 22 and delete 11. Now 22 is a leaf of what remains (2-3-4-52\text{-}3\text{-}4\text{-}5); record its neighbor 33, delete 22. Then 33 is a leaf of 3-4-53\text{-}4\text{-}5; record 44, delete 33. Two vertices, 44 and 55, remain, so the code is (2,3,4)(2, 3, 4) — the pattern for any path 1-2-⋯-n1\text{-}2\text{-}\cdots\text{-}n is simply (2,3,…,n−1)(2, 3, \ldots, n - 1).

Example
Encoding a branching tree

Recall T2T_2 from Leaves and Edge Counts: vertices {1,…,7}\{1,\ldots,7\}, edges 12,23,24,15,56,5712, 23, 24, 15, 56, 57, leaves 3,4,6,73,4,6,7. Lowest leaf 33 has neighbor 22: record 22, delete 33. Now 44 is the lowest leaf, neighbor 22: record 22, delete 44 — this drops 22 to degree 11, making it a leaf itself. Lowest leaf is now 22, neighbor 11: record 11, delete 22, which drops 11 to degree 11. Lowest leaf is 11, neighbor 55: record 55, delete 11. Only 6,76, 7 are leaves of 5-6,5-75\text{-}6, 5\text{-}7; lowest is 66, neighbor 55: record 55, delete 66, leaving just 5,75, 7. The code is (2,2,1,5,5)(2, 2, 1, 5, 5), length 5=7−25 = 7 - 2 as required.

Example
Decoding a code back into a tree

Which tree on {1,…,5}\{1, \ldots, 5\} has Prufer code (3,3,2)(3, 3, 2)? Start every vertex's working degree at 11 plus its count in the code: 33 appears twice and 22 once, so working degrees are 1,1,3,1,11, 1, 3, 1, 1 for 1,2,3,4,51, 2, 3, 4, 5, making 1,4,51, 4, 5 the leaves. Process the code left to right, always pairing with the smallest current leaf: the first 33 pairs with leaf 11 (edge 1313), dropping 33 to degree 22; the second 33 pairs with the next smallest leaf, 44 (edge 3434), dropping 33 to degree 11 — so 33 itself becomes a leaf; the last entry, 22, now pairs with the smallest leaf, which is 33 (edge 2323), dropping 22 to degree 11. Two vertices are left unpaired, 22 and 55, so close with edge 2525. The tree is 13,34,23,2513, 34, 23, 25 — four edges on five vertices, as required.

Side note
Where it goes wrong

Cayleys Formula counts LABELED trees, not tree shapes. On 44 vertices there are only 22 shapes — the path and the star — yet the formula gives 42=164^2 = 16. The star has one center of degree 33, and there are 44 ways to choose which label is the center, giving 44 labeled stars; the other 16−4=1216 - 4 = 12 labeled trees are all paths (each of the 4!/2=124!/2 = 12 orderings of the 44 labels along a path, dividing by 22 for the two directions you can read it). Counting shapes and counting labelings are different questions.

Try it
Try it: how many labeled trees

By Cayley's Formula, how many labeled trees are there on 66 vertices?

Show the answer

nn−2=64=1296n^{n-2} = 6^4 = \mathbf{1296}.

The Matrix-Tree Theorem

Concept
Kirchhoff's theorem

The Laplacian of a graph GG on nn vertices is L=D−AL = D - A, where DD is the diagonal matrix of degrees and AA is the adjacency matrix. Delete any one row and the matching column from LL to get an (n−1)×(n−1)(n-1)\times(n-1) matrix L0L_0. Then det⁡(L0)\det(L_0) equals the number of spanning trees of GG — the Matrix-Tree Theorem. The result does not depend on which vertex's row and column were deleted.

This turns a search over exponentially many edge-subsets into a single determinant. It also ties the whole topic together: Cayleys Formula counted spanning trees of KnK_n by a bijection, and this section recomputes the very same numbers by linear algebra, giving two independent proofs of one fact. The theorem generalizes immediately to weighted graphs (replace 11s in AA by the edge weights) and is the engine behind Kirchhoffs circuit laws, where it counts spanning trees to compute effective resistance.

Example
K4K_4: the Laplacian recovers Cayley's count

Every vertex of K4K_4 has degree 33 and is adjacent to the other three, so L=(3−1−1−1−13−1−1−1−13−1−1−1−13)L = \begin{pmatrix} 3 & -1 & -1 & -1 \\ -1 & 3 & -1 & -1 \\ -1 & -1 & 3 & -1 \\ -1 & -1 & -1 & 3 \end{pmatrix}. Deleting the last row and column leaves L0=(3−1−1−13−1−1−13)L_0 = \begin{pmatrix} 3 & -1 & -1 \\ -1 & 3 & -1 \\ -1 & -1 & 3 \end{pmatrix}, with det⁡(L0)=3(9−1)−(−1)(−3−1)+(−1)(1+3)=24−4−4=16\det(L_0) = 3(9 - 1) - (-1)(-3 - 1) + (-1)(1 + 3) = 24 - 4 - 4 = 16. This matches Cayleys Formula exactly, since every labeled tree on 44 vertices is a subgraph of the complete graph K4K_4: 44−2=164^{4-2} = 16.

Example
G3G_3: checking the hand count from Spanning Trees

Recall G3G_3 (vertices {1,2,3,4}\{1,2,3,4\}, edges 12,23,34,41,1312, 23, 34, 41, 13) from Spanning Trees, where direct case-counting found 88 spanning trees. Its degrees are deg⁡(1)=deg⁡(3)=3\deg(1)=\deg(3)=3, deg⁡(2)=deg⁡(4)=2\deg(2)=\deg(4)=2, giving L=(3−1−1−1−12−10−1−13−1−10−12)L = \begin{pmatrix} 3 & -1 & -1 & -1 \\ -1 & 2 & -1 & 0 \\ -1 & -1 & 3 & -1 \\ -1 & 0 & -1 & 2 \end{pmatrix}. Deleting row/column 44 leaves L0=(3−1−1−12−1−1−13)L_0 = \begin{pmatrix} 3 & -1 & -1 \\ -1 & 2 & -1 \\ -1 & -1 & 3 \end{pmatrix}, and det⁡(L0)=3(6−1)−(−1)(−3−1)+(−1)(1+2)=15−4−3=8\det(L_0) = 3(6-1) - (-1)(-3-1) + (-1)(1+2) = 15 - 4 - 3 = 8 — agreeing with the case count, now from a completely different method.

Example
A genuine count: spanning trees of K2,3K_{2,3}

How many spanning trees does the complete bipartite graph K2,3K_{2,3} have (parts {1,2}\{1,2\} and {3,4,5}\{3,4,5\}, all 66 cross edges present)? Vertices 1,21,2 have degree 33; vertices 3,4,53,4,5 have degree 22. The Laplacian is L=(30−1−1−103−1−1−1−1−1200−1−1020−1−1002)L = \begin{pmatrix} 3 & 0 & -1 & -1 & -1 \\ 0 & 3 & -1 & -1 & -1 \\ -1 & -1 & 2 & 0 & 0 \\ -1 & -1 & 0 & 2 & 0 \\ -1 & -1 & 0 & 0 & 2 \end{pmatrix}, and deleting the last row and column gives a 4×44\times4 determinant equal to 1212. This matches the general formula for complete bipartite graphs, mn−1nm−1m^{n-1}n^{m-1} spanning trees for Km,nK_{m,n}: with m=2,n=3m=2, n=3, 23−1⋅32−1=4⋅3=122^{3-1}\cdot3^{2-1} = 4\cdot3 = 12.

Side note
Where it goes wrong

Using the FULL n×nn \times n Laplacian instead of a cofactor. Every row of LL sums to 00 (each vertex's degree cancels its row of −1-1s), so LL itself is always singular and det⁡(L)=0\det(L) = 0 for every graph, tree or not — that determinant carries no information. Deleting one row and the matching column breaks the dependency; the theorem only works on that smaller matrix, and any single choice of deleted vertex gives the same answer.

Try it
Try it: a triangle with a pendant

Vertices {1,2,3,4}\{1,2,3,4\}, edges 12,23,13,3412, 23, 13, 34 (a triangle with one extra edge to 44). Use the Matrix-Tree Theorem to find the number of spanning trees.

Show the answer

Degrees are deg⁡(1)=deg⁡(2)=2\deg(1)=\deg(2)=2, deg⁡(3)=3\deg(3)=3, deg⁡(4)=1\deg(4)=1, so L0L_0 (deleting row/column 44) is (2−1−1−12−1−1−13)\begin{pmatrix} 2 & -1 & -1 \\ -1 & 2 & -1 \\ -1 & -1 & 3 \end{pmatrix}, with determinant 2(6−1)−(−1)(−3−1)+(−1)(1+2)=10−4−3=32(6-1) - (-1)(-3-1) + (-1)(1+2) = 10 - 4 - 3 = 3. Directly: the triangle alone has 33 spanning trees (drop any one of its 33 edges), and the pendant edge 3434 is a bridge every spanning tree must keep, so the count stays 3\mathbf{3}.

Why It Works

First a lemma: a connected graph on nn vertices has at least n−1n - 1 edges. Induct on nn; n=1n = 1 needs 00 edges. For n≥2n \ge 2, remove any vertex vv from connected GG; what remains splits into k≥1k \ge 1 connected pieces with p1,…,pkp_1, \ldots, p_k vertices, ∑pi=n−1\sum p_i = n - 1, each with ≥pi−1\ge p_i - 1 edges by induction. Since GG is connected, vv has at least one edge into every piece, contributing ≥k\ge k more edges, for a total of ≥∑(pi−1)+k=(n−1)+0=n−1\ge \sum(p_i - 1) + k = (n - 1) + 0 = n - 1.(Connected, acyclic) ⇒\Rightarrow (connected, n−1n - 1 edges): induct on nn. If every vertex of an acyclic graph had degree ≥2\ge 2, you could walk forever without reusing an edge, and finiteness would force a repeated vertex, giving a cycle — contradiction. So some vertex vv has degree ≤1\le 1; connectedness with n≥2n \ge 2 rules out degree 00, so deg⁡(v)=1\deg(v) = 1. Removing this leaf leaves a connected, acyclic graph on n−1n - 1 vertices, which by induction has n−2n - 2 edges, so GG has n−1n - 1.(Connected, n−1n - 1 edges) ⇒\Rightarrow (acyclic, n−1n - 1 edges): if GG had a cycle, deleting one cycle edge keeps GG connected (a cycle edge is never a bridge) with only n−2n - 2 edges, contradicting the lemma. So GG is acyclic.(Acyclic, n−1n - 1 edges) ⇒\Rightarrow (connected, acyclic): split GG into its connected components, with p1,…,pcp_1, \ldots, p_c vertices. Each component is connected and acyclic, so by the first implication it has pi−1p_i - 1 edges. Summing, n−1=∑(pi−1)=n−cn - 1 = \sum(p_i - 1) = n - c, so c=1c = 1: GG is connected.

If TT is connected and acyclic and some pair of vertices had two different paths between them, the two paths would diverge at some vertex and later reconverge; the stretch between that divergence and the next shared vertex, read along both paths, is a cycle — contradicting acyclicity. Conversely, unique paths between every pair forces connectedness (paths exist at all) and acyclicity (a cycle would give its two "opposite" vertices two different paths around it). So unique paths is equivalent to (connected, acyclic). the last two properties: every edge uvuv of a tree is a bridge, since deleting it leaves no path from uu to vv (the only path used uvuv itself, by uniqueness). And joining two non-adjacent vertices u,vu, v creates exactly one cycle — the unique tree-path from uu to vv plus the new edge — since any other cycle through the new edge would give u,vu, v a second tree-path, again contradicting uniqueness.

Let TT be a tree with n≥2n \ge 2 vertices, hence n−1n - 1 edges and degree sum 2(n−1)2(n - 1) by the handshake lemma. Connectedness with n≥2n \ge 2 forbids degree 00. If at most one vertex had degree 11, the degree sum would be at least 2(n−1)+1=2n−12(n - 1) + 1 = 2n - 1 (one vertex at 11, the rest at ≥2\ge 2) or at least 2n2n (no vertex at 11) — either way strictly more than 2(n−1)=2n−22(n - 1) = 2n - 2, contradicting the handshake total. So at least two vertices have degree 11.

Encode a tree TT on label set [n]={1,…,n}[n] = \{1, \ldots, n\} by repeatedly deleting its smallest-labeled leaf and recording the neighbor, stopping with 22 vertices left. The key fact is a degree identity: for every vertex vv, deg⁡T(v)=1+count⁡(v)\deg_T(v) = 1 + \operatorname{count}(v), where count⁡(v)\operatorname{count}(v) is the number of times vv appears in the code. List the deleted leaves in order ℓ1,…,ℓn−2\ell_1, \ldots, \ell_{n-2} with recorded neighbors u1,…,un−2u_1, \ldots, u_{n-2}, and the final surviving pair a,ba, b; the n−1n - 1 edges of TT are exactly {ℓi,ui}\{\ell_i, u_i\} for each ii, together with {a,b}\{a, b\}. A vertex v≠a,bv \ne a, b equals some ℓi\ell_i, and its edges are to uiu_i (its own removal edge) and to every earlier leaf for which it was the recorded neighbor — exactly its occurrences among u1,…,un−2u_1, \ldots, u_{n-2} before step ii (it is gone afterward, so no later occurrence is possible). The survivors a,ba, b are never removed, so their degree is entirely occurrences-in-the-code plus the final edge. Either way, deg⁡T(v)=1+count(v)\deg_T(v) = 1 + \text{count}(v). identity makes decoding exact: given a code, a vertex is a current leaf exactly when its remaining count is 00, so the smallest such vertex must be the next ℓi\ell_i — there is no other choice. So a code determines at most one tree, and running the forward process on the tree that produced it reproduces the same code. Encoding is therefore a bijection between trees on [n][n] and sequences in [n]n−2[n]^{n-2}, and there are exactly nn−2n^{n-2} such sequences.

Orient the edges of GG arbitrarily and form the n×mn \times m incidence matrix MM, with Mv,e=+1M_{v,e} = +1 if vv is ees head, −1-1 if its tail, 00 if v∉ev \notin e. Then MMT=LMM^T = L: the diagonal entry at vv sums (±1)2=1(\pm1)^2 = 1 over the edges at vv, giving deg⁡(v)\deg(v), and the off-diagonal entry for u≠vu \ne v is −1-1 for each edge between them, giving −Auv-A_{uv}. Delete one row of MM to get M0M_0, so L0=M0M0TL_0 = M_0 M_0^T. By the CauchyBinet formula, det⁡(L0)=∑Sdet⁡(M0[S])2\det(L_0) = \sum_S \det(M_0[S])^2, summed over all (n−1)(n-1)-subsets SS of edges, where M0[S]M_0[S] keeps only the columns in SS. SS contains a cycle, the columns of M0[S]M_0[S] for that cycles edges sum to zero with alternating signs (traverse the cycle; each vertex on it is entered once and left once, cancelling), so the columns are dependent and det⁡(M0[S])=0\det(M_0[S]) = 0. If SS is acyclic, then — since ∣S∣=n−1|S| = n - 1 — What Makes a Trees equivalences make SS a spanning tree, with at least two leaves (Leaves and Edge Counts), so some leaf of SS survives the one deleted row. That leafs row in M0[S]M_0[S] has a single nonzero entry, ±1\pm1, in the column for its one edge; expanding the determinant along that row reduces det⁡(M0[S])\det(M_0[S]), up to sign, to the same kind of determinant for the smaller spanning tree left after deleting that leaf and its edge. Repeating down to a single edge — a 1×11 \times 1 matrix with entry ±1\pm1 — shows det⁡(M0[S])=±1\det(M_0[S]) = \pm 1 for every spanning tree SS. each (n−1)(n-1)-subset SS contributes 11 to ∑Sdet⁡(M0[S])2\sum_S \det(M_0[S])^2 exactly when it is a spanning tree, and 00 otherwise: det⁡(L0)\det(L_0) is exactly the number of spanning trees of GG.