What Makes a Tree
A graph on 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 edges; (3) acyclic with exactly 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 vertices from one takes at least edges, so a connected graph with exactly edges has no edge to spare for a cycle, and an acyclic graph with 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.
Let have vertices and edges . It has vertices and edges. Tracing from vertex reaches and directly, then through and through — all six vertices, so is connected. With edges already forced to be exactly enough to connect vertices, no edge is free to close a cycle; indeed the unique path from to is , with no alternative route. So is a tree.
Add the edge to , joining two vertices that were not adjacent. Now there are edges on vertices — one too many to stay acyclic — and indeed now form a cycle: , , are all edges. Every degree outside is unchanged; and each gain the new edge, going from degree to degree . 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.
On vertices , take edges (a triangle) together with (a path). That is edges — the right count for a tree — but vertex can never reach vertex : the graph splits into two pieces. So having 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).
The smallest trap: vertices and edges, checked only by counting. On , take the triangle and leave vertex untouched — edges, yet 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.
A connected graph has vertices and edges. Must it be a tree?
Show the answerHide the answer
Yes. Connected with exactly 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
A tree with vertices has edges, so by the handshake lemma . also has at least two leaves (vertices of degree ): if only vertices had degree and the rest had degree , the sum would be at least , a contradiction.
This is the same 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 vertices with 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.
Let have vertices and edges . That is edges. Degrees: , , , and . The sum is , confirming the handshake count, and has four leaves, — more than the minimum of two, which the lemma only guarantees as a floor.
A tree has leaves, and every one of its other vertices has degree exactly . How many vertices does it have? Let be the number of degree- vertices, so and the number of edges is . The handshake lemma gives , i.e. , so and . Check: vertices give edges and degree sum ; directly, as well.
Is the degree sequence of some tree on vertices? Its sum is , so the handshake count is right, and every value is at least . Build one: attach two leaves to a hub (giving degree so far), then chain through degree- vertices to a last leaf , and finish with to bring to degree . The edges are — of them — with degrees , , , matching the sequence exactly.
Matching the handshake sum is not enough either — every degree must also be at least . On vertices, sums to , but a degree- vertex is isolated, and an isolated vertex can never belong to a connected graph. No tree has this degree sequence, sum notwithstanding.
A tree has vertices; of them are leaves, and the remaining all share some degree . Find .
Show the answerHide the answer
With there are edges, so the degree sum is . The leaves contribute , leaving , so .
Spanning Trees
A spanning tree of a connected graph is a subgraph that is a tree and includes every vertex of . 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 has vertices and edges, any spanning tree uses of them, leaving 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.
Let have vertices and edges — a -cycle with one diagonal, edges on vertices, so its circuit rank is . Edge lies on the triangle , so remove it; edge now lies on the remaining cycle , so remove it too. What is left, , is connected (it is the path ) and has edges: a spanning tree, reached by removing exactly the circuit rank's edges.
How many different spanning trees does (above) have? Any spanning tree uses of its edges. Split on the diagonal : if a tree uses , it still needs to reach (via or ) and (via or ) — choices, all acyclic since each just attaches a pendant to edge . If a tree avoids , it must use of the remaining cycle edges ; removing any one of the four from that -cycle leaves a spanning path, giving more trees. In total has spanning trees.
A disconnected graph has no spanning tree at all — not one with fewer edges, but none. Two disjoint triangles on and 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, edges total, two trees). "Spanning tree" always presumes a connected starting graph.
A connected graph has vertices and edges. At minimum, how many edges must be removed to leave a spanning tree?
Show the answerHide the answer
A spanning tree uses edges, so the circuit rank is : exactly four edges must go, one from each independent cycle.
Cayley's Formula and Prufer Codes
The number of labeled trees on vertex set (equivalently, the number of spanning trees of ) is for — Cayleys Formula. The Prufer code proves it by a direct bijection: repeatedly delete the lowest-labeled leaf and record its neighbor, until vertices remain; this produces a sequence in , 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 since each of the slots is an independent choice from labels.
Find the Prufer code of the path . The leaves are and ; the lower one, , has neighbor , so record and delete . Now is a leaf of what remains (); record its neighbor , delete . Then is a leaf of ; record , delete . Two vertices, and , remain, so the code is — the pattern for any path is simply .
Recall from Leaves and Edge Counts: vertices , edges , leaves . Lowest leaf has neighbor : record , delete . Now is the lowest leaf, neighbor : record , delete — this drops to degree , making it a leaf itself. Lowest leaf is now , neighbor : record , delete , which drops to degree . Lowest leaf is , neighbor : record , delete . Only are leaves of ; lowest is , neighbor : record , delete , leaving just . The code is , length as required.
Which tree on has Prufer code ? Start every vertex's working degree at plus its count in the code: appears twice and once, so working degrees are for , making the leaves. Process the code left to right, always pairing with the smallest current leaf: the first pairs with leaf (edge ), dropping to degree ; the second pairs with the next smallest leaf, (edge ), dropping to degree — so itself becomes a leaf; the last entry, , now pairs with the smallest leaf, which is (edge ), dropping to degree . Two vertices are left unpaired, and , so close with edge . The tree is — four edges on five vertices, as required.
Cayleys Formula counts LABELED trees, not tree shapes. On vertices there are only shapes — the path and the star — yet the formula gives . The star has one center of degree , and there are ways to choose which label is the center, giving labeled stars; the other labeled trees are all paths (each of the orderings of the labels along a path, dividing by for the two directions you can read it). Counting shapes and counting labelings are different questions.
By Cayley's Formula, how many labeled trees are there on vertices?
Show the answerHide the answer
.
The Matrix-Tree Theorem
The Laplacian of a graph on vertices is , where is the diagonal matrix of degrees and is the adjacency matrix. Delete any one row and the matching column from to get an matrix . Then equals the number of spanning trees of — 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 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 s in by the edge weights) and is the engine behind Kirchhoffs circuit laws, where it counts spanning trees to compute effective resistance.
Every vertex of has degree and is adjacent to the other three, so . Deleting the last row and column leaves , with . This matches Cayleys Formula exactly, since every labeled tree on vertices is a subgraph of the complete graph : .
Recall (vertices , edges ) from Spanning Trees, where direct case-counting found spanning trees. Its degrees are , , giving . Deleting row/column leaves , and — agreeing with the case count, now from a completely different method.
How many spanning trees does the complete bipartite graph have (parts and , all cross edges present)? Vertices have degree ; vertices have degree . The Laplacian is , and deleting the last row and column gives a determinant equal to . This matches the general formula for complete bipartite graphs, spanning trees for : with , .
Using the FULL Laplacian instead of a cofactor. Every row of sums to (each vertex's degree cancels its row of s), so itself is always singular and 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.
Vertices , edges (a triangle with one extra edge to ). Use the Matrix-Tree Theorem to find the number of spanning trees.
Show the answerHide the answer
Degrees are , , , so (deleting row/column ) is , with determinant . Directly: the triangle alone has spanning trees (drop any one of its edges), and the pendant edge is a bridge every spanning tree must keep, so the count stays .
Why It Works
First a lemma: a connected graph on vertices has at least edges. Induct on ; needs edges. For , remove any vertex from connected ; what remains splits into connected pieces with vertices, , each with edges by induction. Since is connected, has at least one edge into every piece, contributing more edges, for a total of .(Connected, acyclic) (connected, edges): induct on . If every vertex of an acyclic graph had degree , you could walk forever without reusing an edge, and finiteness would force a repeated vertex, giving a cycle — contradiction. So some vertex has degree ; connectedness with rules out degree , so . Removing this leaf leaves a connected, acyclic graph on vertices, which by induction has edges, so has .(Connected, edges) (acyclic, edges): if had a cycle, deleting one cycle edge keeps connected (a cycle edge is never a bridge) with only edges, contradicting the lemma. So is acyclic.(Acyclic, edges) (connected, acyclic): split into its connected components, with vertices. Each component is connected and acyclic, so by the first implication it has edges. Summing, , so : is connected.
If 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 of a tree is a bridge, since deleting it leaves no path from to (the only path used itself, by uniqueness). And joining two non-adjacent vertices creates exactly one cycle — the unique tree-path from to plus the new edge — since any other cycle through the new edge would give a second tree-path, again contradicting uniqueness.
Let be a tree with vertices, hence edges and degree sum by the handshake lemma. Connectedness with forbids degree . If at most one vertex had degree , the degree sum would be at least (one vertex at , the rest at ) or at least (no vertex at ) — either way strictly more than , contradicting the handshake total. So at least two vertices have degree .
Encode a tree on label set by repeatedly deleting its smallest-labeled leaf and recording the neighbor, stopping with vertices left. The key fact is a degree identity: for every vertex , , where is the number of times appears in the code. List the deleted leaves in order with recorded neighbors , and the final surviving pair ; the edges of are exactly for each , together with . A vertex equals some , and its edges are to (its own removal edge) and to every earlier leaf for which it was the recorded neighbor — exactly its occurrences among before step (it is gone afterward, so no later occurrence is possible). The survivors are never removed, so their degree is entirely occurrences-in-the-code plus the final edge. Either way, . identity makes decoding exact: given a code, a vertex is a current leaf exactly when its remaining count is , so the smallest such vertex must be the next — 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 and sequences in , and there are exactly such sequences.
Orient the edges of arbitrarily and form the incidence matrix , with if is s head, if its tail, if . Then : the diagonal entry at sums over the edges at , giving , and the off-diagonal entry for is for each edge between them, giving . Delete one row of to get , so . By the CauchyBinet formula, , summed over all -subsets of edges, where keeps only the columns in . contains a cycle, the columns of 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 . If is acyclic, then — since — What Makes a Trees equivalences make a spanning tree, with at least two leaves (Leaves and Edge Counts), so some leaf of survives the one deleted row. That leafs row in has a single nonzero entry, , in the column for its one edge; expanding the determinant along that row reduces , 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 matrix with entry — shows for every spanning tree . each -subset contributes to exactly when it is a spanning tree, and otherwise: is exactly the number of spanning trees of .