Foundations

Trees in Graph Theory

A tree has seven equivalent definitions, and that is exactly why it is the most useful special case in the subject: seven definitions means seven ways to prove things. This guide works through the equivalence theorem and its proof, the leaf lemma that drives every induction, how many trees exist, and how to find a tree’s centre and diameter in linear time.

24 Min Read Updated: September 2026 Beginner Level
Mohammed Islam Hadjoudj
Mohammed Islam Hadjoudj
Expert Operations Research Engineer

1. A tree has seven definitions, and they are all the same one

Ask three people to define a tree and you will get three answers. One says it is a connected graph with no cycles. Another says it is a graph with exactly one path between any two vertices. A third says it is a connected graph with n - 1 edges. All three are right, and so are four more definitions besides, because these conditions are equivalent: any graph satisfying one satisfies all of them.

That is unusual, and it is the reason trees are the most useful special case in the subject. A structure with seven equivalent characterisations gives you seven different ways to prove something about it, and in practice you pick whichever one makes the proof shortest.

Start with the standard definition, the one in Diestel and in Bondy and Murty:

A tree is a connected acyclic graph. A graph whose components are all trees is a forest. A vertex of degree 1 in a tree is a leaf.

Everything below is about a finite simple, undirected graph, which is the standard setting. A tree cannot have a loop or a parallel edge anyway, since either one is a cycle.

A tree on eight labelled vertices. Vertex 3 joins vertices 1, 2 and 4; vertex 4 joins 3 and 5; vertex 5 joins 4, 6 and 7; vertex 7 joins 5 and 8. Leaves 1, 2, 6 and 8 are marked in green, internal vertices 3, 4, 5 and 7 in blue, and each vertex is labelled with its degree. A panel records eight vertices, seven edges, degree sum fourteen, and four leaves.
The running example for the whole article: eight vertices, seven edges, four leaves. Every claim below is checked against this tree.

Written out, the running example is

V = {1, 2, 3, 4, 5, 6, 7, 8}
E = { {1,3}, {2,3}, {3,4}, {4,5}, {5,6}, {5,7}, {7,8} }

degrees   1:1   2:1   3:3   4:2   5:3   6:1   7:2   8:1
n = 8     m = 7 = n - 1      degree sum = 14 = 2m      leaves: 1, 2, 6, 8

2. The equivalence theorem, and how its proof works

Here is the result in full. It appears in essentially this form in West, in Bondy and Murty, and in Diestel, and it is worth memorising because each line is a tool.

Theorem. For a graph G on n vertices, the following are equivalent:
(1) G is a tree, that is, connected and acyclic.
(2) Any two vertices of G are joined by exactly one path.
(3) G is connected and has n - 1 edges.
(4) G is acyclic and has n - 1 edges.
(5) G is connected, and removing any single edge disconnects it (minimally connected).
(6) G is acyclic, and adding any single edge creates a cycle (maximally acyclic).
(7) G is connected and every edge is a bridge.

The proof is not one argument but a cycle of implications, each of them short. It is worth seeing the shape, because it explains why the conditions feel so different from one another and yet describe the same object.

StepWhy it holds
(1) → (2)Connectivity gives at least one path. If two distinct paths joined the same pair, their union would contain a cycle, contradicting acyclicity.
(2) → (5)One path between every pair means connected. Deleting the edge {u, v} destroys the only path from u to v, so the graph falls apart.
(5) → (1)If a cycle existed, any edge of it could be deleted while leaving the graph connected, since the rest of the cycle still joins its ends. So there is no cycle.
(1) → (3)Induction on n. A tree has a leaf (section 3); delete it and you have a tree on n - 1 vertices, which by induction has n - 2 edges. Put the leaf back and you have n - 1.
(3) → (4)Suppose G were connected with n - 1 edges and still had a cycle. Delete one edge of that cycle: the graph stays connected, but now has only n - 2 edges, and a connected graph on n vertices needs at least n - 1. The contradiction rules out the cycle.
(4) → (1)An acyclic graph with k components and n vertices has exactly n - k edges (section 4). With n - 1 edges, k = 1, so it is connected.
(1) ↔ (6)Adding {u, v} to a tree closes the unique existing u to v path into a cycle. Conversely, maximal acyclicity forces connectivity, since two vertices in different components could be joined without creating any cycle.

Two of these deserve emphasis because they are the ones people actually use.

"Connected and n - 1 edges" is the cheapest test. Counting edges is O(m) and a connectivity check is O(n + m), so you can decide treehood in linear time without ever looking for a cycle. Note that neither half suffices alone: a triangle plus an isolated vertex has 4 vertices and 3 edges but is not a tree, and neither is a 4-cycle, which is connected with 4 edges.

"Minimally connected" and "maximally acyclic" are the same object seen from two directions. A tree sits exactly on the boundary: it has as few edges as connectivity allows and as many as acyclicity allows. That is why trees turn up whenever a problem asks for a cheapest connecting structure, which is precisely the minimum spanning tree problem.

All seven conditions hold on the running example, and each was checked directly: it is connected, acyclic, has 7 edges on 8 vertices, has exactly one path between each of the 28 vertex pairs, every one of its 7 edges is a bridge, and every one of the 21 missing edges closes a cycle when added.

3. The leaf lemma

One small result carries most of the inductive proofs in the subject.

Leaf lemma. Every finite tree with at least two vertices has at least two leaves.

The proof is a favourite because it uses nothing but the definition. Take a longest path P in the tree, say from u to v. Such a path exists because the tree is finite. Now consider u. If u had a neighbour w outside P, then P could be extended by that edge, contradicting maximality. If u had a second neighbour on P, that would close a cycle, contradicting acyclicity. So u has exactly one neighbour and is a leaf, and the same argument applies to v.

Two consequences follow immediately and both are used constantly:

The running example has four leaves, 1, 2, 6 and 8, comfortably more than the guaranteed two. A useful sanity check when debugging tree code: if your structure claims to be a tree and reports fewer than two leaves, something is wrong, and the usual culprit is an accidental cycle.

The lemma is also exactly what fails on infinite graphs. The one-way infinite path has a single leaf and the two-way infinite path has none at all, which is one of the cleanest illustrations of what finiteness was buying, covered in the guide to finite and infinite graphs.

4. Forests, and counting components for free

A forest is an acyclic graph, connected or not. Every component of a forest is a tree, and that gives a counting identity worth knowing by heart:

A forest with n vertices and k components has exactly n - k edges.

The proof is one line: each component is a tree, so a component with ni vertices contributes ni - 1 edges, and summing over the k components gives n - k. Setting k = 1 recovers the tree case.

Read the identity backwards and it becomes a tool rather than a fact:

k = n - m        the number of components of a forest,
                 computed from its size alone, with no traversal

That is genuinely useful. If you know a graph is acyclic, counting its vertices and edges tells you how many pieces it is in without running a search. It is also the identity behind the standard union-find invariant: every successful union merges two components and adds one edge, so the running count n - (unions so far) is the number of components at any moment.

One warning. The identity assumes acyclicity. For a general graph, m ≥ n - k always holds, with equality exactly when the graph is a forest, so a graph with more edges than n - k necessarily contains a cycle. That inequality is the fastest way to prove a graph has a cycle without finding one: if m ≥ n, there is a cycle somewhere.

5. Spanning trees

A spanning tree of a connected graph G is a subgraph that is a tree and includes every vertex of G. It is the minimal skeleton that keeps the graph in one piece.

Every connected finite graph has one, and the constructive proof is worth knowing because it is also an algorithm: while a cycle exists, delete any edge of it. Deleting a cycle edge cannot disconnect the graph, since the rest of the cycle still joins its endpoints, and the process terminates because each step removes an edge. What remains is connected and acyclic. Equivalently, and more practically, the tree of discovery edges produced by any BFS or DFS traversal is already a spanning tree, found in O(n + m).

Three facts about spanning trees that come up repeatedly:

For infinite graphs the statement "every connected graph has a spanning tree" is still true but needs the axiom of choice, and is in fact equivalent to it. That boundary is discussed in the finite and infinite graphs guide.

6. Counting labelled trees: Cayley's formula

How many different trees can be built on a fixed set of n labelled vertices? The answer is one of the most quotable results in combinatorics, published by Arthur Cayley in 1889.

Cayley's formula. The number of labelled trees on n vertices is nn-2.

The first few values grow fast, and they are worth seeing because the smallest ones can be checked by hand:

nnn-2Check
21The single edge, and nothing else is possible
33A path on 3 vertices, once for each choice of middle vertex
416Verified by exhaustive enumeration of all edge subsets
5125Verified the same way
61296Already past hand-checking

The counts for n = 4 and n = 5 above are not quoted from a book; they were produced by enumerating every subset of n - 1 edges from the C(n, 2) candidates and keeping the connected ones, giving 16 and 125 exactly.

A word on what "labelled" means, because the distinction is the whole subject of section 9. Cayley counts trees whose vertices are distinguishable, so the path 1 - 2 - 3 and the path 2 - 1 - 3 are different trees even though they have the same shape. Strip the labels and there is only one shape of tree on three vertices.

Several proofs of the formula exist, including a double-counting argument on rooted forests and a determinant argument via the matrix-tree theorem. The most illuminating is a bijection, and it is short enough to work through completely.

7. The Prüfer bijection, worked end to end

Heinz Prüfer gave a proof of Cayley's formula in 1918 by constructing an explicit bijection between labelled trees on n vertices and sequences of length n - 2 drawn from {1, …, n}. Since there are exactly nn-2 such sequences, the formula follows at once.

The eight vertex example tree beside a six step encoding table. At each step the smallest remaining leaf is removed and its neighbour is written down: leaf 1 gives 3, leaf 2 gives 3, leaf 3 gives 4, leaf 6 gives 5, leaf 4 gives 5, leaf 5 gives 7, leaving the Prüfer sequence 3, 3, 4, 5, 5, 7. A note records that each vertex appears one less time than its degree.
Encoding strips the smallest leaf repeatedly and records its neighbour. Six removals reduce eight vertices to two, which is why the sequence has length n minus 2.

Encoding. While more than two vertices remain, find the leaf with the smallest label, write down the label of its unique neighbour, and delete the leaf. Stop when two vertices are left. On the running example this produces, step by step:

remove leaf 1  →  write 3        remaining: 2,3,4,5,6,7,8
remove leaf 2  →  write 3        remaining: 3,4,5,6,7,8
remove leaf 3  →  write 4        remaining: 4,5,6,7,8
remove leaf 6  →  write 5        remaining: 4,5,7,8
remove leaf 4  →  write 5        remaining: 5,7,8
remove leaf 5  →  write 7        remaining: 7,8

Prüfer sequence:  (3, 3, 4, 5, 5, 7)        length 6 = n - 2

Decoding. The inverse runs the same idea backwards. Give every vertex a counter equal to one plus the number of times it appears in the sequence, which will be its degree. Then repeatedly take the smallest vertex whose counter is 1 and is not yet used, join it to the first remaining entry of the sequence, and decrement both counters. When the sequence is exhausted, join the two vertices still holding a counter of 1. Running this on (3, 3, 4, 5, 5, 7) returns exactly the original edge set, which is what makes the correspondence a bijection rather than merely a summary.

The single most useful property of the encoding is this:

Vertex v appears in the Prüfer sequence exactly deg(v) - 1 times. In particular, the leaves are precisely the labels that never appear.

Check it against the running example. Vertex 3 has degree 3 and appears twice; vertex 5 has degree 3 and appears twice; vertices 4 and 7 have degree 2 and appear once each; and the leaves 1, 2, 6 and 8 appear not at all. That correspondence turns questions about degree sequences into questions about how often symbols occur in a string, which is why Prüfer sequences are the standard tool for counting trees with prescribed degrees and for sampling a labelled tree uniformly at random: generate a random sequence of length n - 2 and decode it.

8. The matrix-tree theorem

Cayley's formula counts spanning trees of the complete graph. Kirchhoff's matrix-tree theorem, which predates it by four decades and came out of his work on electrical networks in 1847, counts the spanning trees of any graph.

Build the Laplacian matrix L = D - A, where D is the diagonal matrix of degrees and A is the adjacency matrix. Then:

Matrix-tree theorem. Delete any one row and the corresponding column from L. The determinant of the remaining (n-1) × (n-1) matrix is the number of spanning trees of the graph. The choice of which row and column to delete does not matter.

Three computations make the theorem concrete, and all three were carried out rather than quoted:

GraphSpanning treesCross-check
K4, the complete graph on 4 vertices16Agrees with Cayley: 44-2 = 16
C4, the 4-cycle4Delete any one of the 4 edges and a spanning tree remains
The running example tree1A tree is its own only spanning tree

The cycle case is the one to hold on to as intuition: a cycle on k vertices has exactly k spanning trees, one for each edge you choose to drop. The theorem also explains a remark from the guide to multigraphs: parallel edges genuinely change the spanning tree count, because they enter the Laplacian as off-diagonal multiplicities, so two vertices joined by two parallel edges have two spanning trees rather than one.

9. Unlabelled trees: a much harder question

Cayley's formula is clean because labels make trees easy to tell apart. Ask instead how many trees there are up to isomorphism, meaning how many distinct shapes exist, and the problem becomes genuinely hard.

nLabelled trees (nn-2)Unlabelled trees
111
211
331
4162
51253
612966
71680711

The two columns tell completely different stories. The labelled count has a one-line closed form; the unlabelled count has none. There is no known formula for the number of trees on n vertices up to isomorphism, only a generating-function treatment and an asymptotic result due to Richard Otter in 1948, which shows the count grows like C · αn n-5/2 for constants worked out numerically.

The reason for the gap is symmetry. Dividing the labelled count by n! would be right only if every tree had trivial automorphism group, and most do not: a path can be reflected, a star can have its leaves permuted arbitrarily, and each symmetry means several labellings collapse to the same shape. Counting orbits under the symmetric group is exactly the hard part, and it is the reason the problem needs Pólya's enumeration machinery rather than a formula.

For a working programmer the practical form of this distinction is tree isomorphism testing: deciding whether two trees have the same shape. Unlike general graph isomorphism, this is solvable in linear time, by canonically hashing each subtree bottom up from the leaves and comparing the results at the centre. That the general problem is hard while the tree case is easy is one more instance of the pattern running through this whole article.

10. Centres, radius and diameter

The eccentricity of a vertex is its greatest distance to any other vertex. The radius is the smallest eccentricity in the graph, the diameter the largest, and the centre is the set of vertices attaining the radius. For trees these have unusually clean behaviour, first worked out by Camille Jordan in 1869.

Jordan's theorem. The centre of a tree consists of either one vertex or two adjacent vertices.

Never three, never two non-adjacent ones. Compare that with a cycle, where every vertex is in the centre, and the sharpness of the tree case is clear.

The eight vertex example tree shown in three stages of leaf stripping. Stage one removes leaves 1, 2, 6 and 8. Stage two removes the new leaves 3 and 7. What remains is the pair 4 and 5, which are adjacent, and these form the centre. A side panel lists every eccentricity: vertices 1, 2 and 8 have eccentricity 5, vertices 3, 6 and 7 have 4, and vertices 4 and 5 have 3, so the radius is 3 and the diameter is 5.
Peel the leaves, then peel the new leaves, and keep going. Whatever survives is the centre, which for this tree is the adjacent pair 4 and 5.

The proof doubles as the algorithm. Repeatedly delete all current leaves simultaneously. Every deletion reduces the eccentricity of every surviving vertex by exactly 1, so it preserves which vertices are minimal, and the process ends with one or two vertices left. On the running example:

start        1 2 3 4 5 6 7 8
strip leaves 1, 2, 6, 8   →   remaining  3 4 5 7
strip leaves 3, 7         →   remaining  4 5      ← the centre

eccentricities   1:5  2:5  3:4  4:3  5:3  6:4  7:4  8:5
radius 3     diameter 5     centre {4, 5}, adjacent as Jordan requires

The leaf-stripping result was checked against a direct computation of all eight eccentricities, and the two agree exactly: the vertices of minimum eccentricity are precisely 4 and 5. The algorithm runs in O(n), which is why it is the standard way to root a tree "in the middle", for instance before canonical hashing in isomorphism testing.

One more identity holds in trees and is worth remembering:

radius = ⌈diameter / 2⌉        here: 3 = ⌈5 / 2⌉

It follows because a tree's diameter is realised by a unique path, and the centre sits at that path's midpoint. In a general graph only the weaker radius ≤ diameter ≤ 2 · radius holds.

11. Distance in trees, and the double BFS trick

Because there is exactly one path between any two vertices, distance in a tree is simpler than in any other class of graph. There is nothing to optimise: the unique path is the shortest path, so no weights, no priority queue and no Dijkstra are needed to find it.

That uniqueness gives a neat and widely used algorithm for the diameter:

Double BFS. Run a breadth first search from any vertex and let a be a farthest vertex found. Run a second search from a and let b be a farthest vertex from it. Then the path from a to b is a diameter, and dist(a, b) is the diameter's length.

Two linear passes, no weights, no cleverness. On the running example, starting at vertex 1 the search reaches vertex 8 as a farthest vertex, and a second search from 8 returns vertex 1 at distance 5, matching the true diameter computed by taking the maximum over all eccentricities.

The reason it works is worth stating, because the trick fails on general graphs and people transplant it anyway. The key claim is that a farthest vertex from any starting point is always an endpoint of some diameter. In a tree this holds because the unique paths force the farthest vertex to lie at the end of the longest path; in a graph with cycles the claim is simply false, and the two-pass method can return an underestimate. On a general graph, computing the diameter needs all-pairs distances.

Some other distance facts that hold in trees and nowhere else in general:

12. Free trees, rooted trees, ordered trees

Everything so far has been about free trees: connected acyclic graphs with no distinguished vertex and no ordering among the neighbours of any vertex. Computer science almost always works with something more structured, and Knuth's The Art of Computer Programming is careful to separate the three levels, because the counts differ at every one.

ObjectExtra structureExample count on 3 nodes
Free treeNone. Just a connected acyclic graph1 shape
Rooted treeOne vertex is designated the root, which orients every edge away from it2 shapes: a path rooted at an end, or at the middle
Ordered treeThe children of each node have a left-to-right order2 shapes, and the distinction bites from 4 nodes upwards

Rooting is not a change to the graph, it is a change to the question. The underlying edge set is identical; what a root adds is a direction, and with it the whole vocabulary of parent, child, ancestor, descendant, depth and height, which the companion guide on rooted trees covers in detail along with the standard traversals.

The counting difference is the sharpest way to see that these really are different objects. Ordered binary trees on n nodes are counted by the Catalan numbers, giving 1, 1, 2, 5, 14, 42 for n = 0 to 5, whereas free trees on the same number of vertices are far fewer. Every extra piece of structure you insist on multiplies the number of distinct objects.

A practical note that follows from section 10: when an algorithm needs a root and none is given, rooting at the centre is usually the right default. It minimises the height, which bounds the depth of any recursion you run over the tree.

13. Where trees show up in computing

Trees are the most common structure in computing that is genuinely a graph, and it is worth separating the cases where the tree is the data from those where it is a certificate produced by an algorithm.

Trees as data. The hierarchy is the point:

Trees as certificates. Here the tree is the output of an algorithm and encodes a proof:

One clarification worth making, because the terminology misleads people: a Git commit history is not a tree. A merge commit has two parents, so the history is a directed acyclic graph. Git's "tree" objects are something else entirely, namely the directory snapshots. The distinction between a DAG and a tree is precisely that a tree has a unique path between any two nodes, and a merge destroys that.

14. Common mistakes

15. Glossary

TermMeaning
TreeA connected acyclic graph; equivalently any of the seven conditions in section 2
ForestAn acyclic graph; every component is a tree. With n vertices and k components it has n - k edges
LeafA vertex of degree 1. Every finite tree with at least 2 vertices has at least 2
Spanning treeA subgraph that is a tree and touches every vertex of the host graph
BridgeAn edge whose removal disconnects the graph. In a tree, every edge is one
EccentricityThe greatest distance from a vertex to any other
Radius, diameterThe minimum and maximum eccentricity. In a tree, radius = ⌈diameter / 2⌉
CentreThe vertices of minimum eccentricity. In a tree this is one vertex or two adjacent ones
Cayley's formulaThere are nn-2 labelled trees on n vertices
Prüfer sequenceA length n - 2 encoding of a labelled tree; vertex v appears deg(v) - 1 times
LaplacianL = D - A; any cofactor counts the graph's spanning trees
Free vs rooted treeA free tree has no distinguished vertex; rooting adds a root and orients every edge away from it

16. Frequently asked questions

What is a tree in graph theory?

A connected graph with no cycles. Six other conditions describe exactly the same object: exactly one path between every pair of vertices; connected with n-1 edges; acyclic with n-1 edges; minimally connected, so removing any edge disconnects it; maximally acyclic, so adding any edge creates a cycle; and connected with every edge a bridge. Any one of them can be taken as the definition, which is why trees are so convenient to prove things about.

Why does a tree have exactly n - 1 edges?

By induction, using the fact that every finite tree with at least two vertices has a leaf. Delete a leaf and its single edge: what remains is still connected and still acyclic, so it is a tree on n-1 vertices, which by induction has n-2 edges. Adding the leaf back gives n-1. The same counting extends to forests: a forest with n vertices and k components has exactly n-k edges, so the component count can be read off as n minus the edge count.

How many trees are there on n vertices?

It depends whether the vertices are labelled. With labels, Cayley's formula of 1889 gives exactly n to the power n-2: that is 16 trees on 4 vertices and 125 on 5. Without labels, counting distinct shapes, there is no closed formula at all: the counts run 1, 1, 1, 2, 3, 6, 11 for n = 1 to 7, and only an asymptotic result due to Otter in 1948 is known. The gap exists because trees have symmetries, so many labellings collapse to the same shape.

What is a Prüfer sequence used for?

It is a bijection between labelled trees on n vertices and sequences of length n-2 over the labels, which proves Cayley's formula immediately since there are n to the power n-2 such sequences. It is also practical: because a vertex appears exactly deg(v)-1 times in the sequence, questions about degree sequences become questions about symbol frequencies, and you can sample a uniformly random labelled tree simply by generating a random sequence and decoding it.

How do I find the centre or the diameter of a tree?

For the centre, repeatedly delete all current leaves at once until one or two vertices remain; those are the centre, and Jordan proved in 1869 that a tree's centre is always one vertex or two adjacent ones. For the diameter, run a breadth first search from any vertex, take a farthest vertex found, and run a second search from there: the greatest distance in the second pass is the diameter. Both are linear time. The double search trick is valid only on trees, and can underestimate on a graph with cycles.

What is the difference between a tree, a spanning tree and a DAG?

A tree is an undirected connected acyclic graph. A spanning tree is a tree that sits inside a larger connected graph and reaches all of its vertices, so a graph has many spanning trees while a tree is its own only one. A DAG is directed and has no directed cycle, but it may well have several paths between two nodes, which no tree can. That last point is why a Git commit history, where a merge has two parents, is a DAG and not a tree.

17. References

Sources for the definitions, theorems and attributions above, together with the standard texts in which this material is developed, listed in chronological order.

  1. Kirchhoff, G. (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 148(12), 497 to 508. The matrix-tree theorem.
  2. Jordan, C. (1869). "Sur les assemblages de lignes." Journal für die reine und angewandte Mathematik 70, 185 to 190. The centre of a tree is one vertex or two adjacent vertices.
  3. Cayley, A. (1889). "A Theorem on Trees." Quarterly Journal of Pure and Applied Mathematics 23, 376 to 378.
  4. Prüfer, H. (1918). "Neuer Beweis eines Satzes über Permutationen." Archiv der Mathematik und Physik 27, 142 to 144. The bijection of section 7.
  5. Borůvka, O. (1926). "O jistém problému minimálním." Práce Moravské Přírodovědecké Společnosti 3, 37 to 58.
  6. König, D. (1936). Theorie der endlichen und unendlichen Graphen. Leipzig: Akademische Verlagsgesellschaft.
  7. Otter, R. (1948). "The Number of Trees." Annals of Mathematics 49(3), 583 to 599. Asymptotics for unlabelled trees.
  8. Kruskal, J. B. (1956). "On the Shortest Spanning Subtree of a Graph and the Traveling Salesman Problem." Proceedings of the American Mathematical Society 7(1), 48 to 50.
  9. Prim, R. C. (1957). "Shortest Connection Networks and Some Generalizations." Bell System Technical Journal 36(6), 1389 to 1401.
  10. Harary, F. (1969). Graph Theory. Reading, Massachusetts: Addison-Wesley.
  11. Knuth, D. E. (1997). The Art of Computer Programming, Volume 1: Fundamental Algorithms, 3rd edition, section 2.3. Reading, Massachusetts: Addison-Wesley. The free, rooted and ordered distinction.
  12. West, D. B. (2001). Introduction to Graph Theory, 2nd edition. Upper Saddle River: Prentice Hall. Chapter 2 develops trees and distance.
  13. Bondy, J. A. and Murty, U. S. R. (2008). Graph Theory. Graduate Texts in Mathematics 244. London: Springer.
  14. Cormen, T. H., Leiserson, C. E., Rivest, R. L. and Stein, C. (2009). Introduction to Algorithms, 3rd edition. Cambridge, Massachusetts: MIT Press.
  15. Diestel, R. (2017). Graph Theory, 5th edition. Graduate Texts in Mathematics 173. Berlin: Springer. Section 1.5 covers trees and forests.

Build a tree and try to break it

Lay out the eight-vertex example, count the edges, then add one more edge anywhere and watch a cycle appear. Delete an edge instead and watch it fall into exactly two pieces. Both are the equivalence theorem in action.

Open the visualizer

Build a Tree and Try to Break It

Lay out the eight-vertex example, count the edges, then add one edge anywhere and watch a cycle appear. Delete one instead and watch the tree fall into exactly two pieces. That is the equivalence theorem, visible.

Launch the Spanning Tree Visualizer