A topic in the Open Knowledge Graph — a free, open map of 15,290 topics and the order to learn them in.

Trees, Forests, and Spanning Trees

College Depth 83 in the knowledge graph ☐ I know this ☆ Set as goal
2topics build on this
401prerequisites beneath it
See this on the map →
Introduction to Graph TheoryChromatic Polynomial and Counting Proper Colorings+2 more→→Minimum Spanning Trees and Optimization
graph-theory trees

Core Idea

A tree is a connected acyclic graph with n vertices and n-1 edges. A forest is a disjoint union of trees. A spanning tree of a graph is a subgraph that includes all vertices and is itself a tree. Trees are fundamental in computer science and have unique shortest paths between any two vertices.

Explainer

From your graph theory prerequisite, you know a graph is a set of vertices connected by edges, and you can ask about paths, cycles, and connectivity. A tree is defined by two simple conditions held simultaneously: the graph is connected (you can reach any vertex from any other) and it contains no cycles (there is no closed loop). The remarkable thing is that these two conditions together force the edge count: any tree on n vertices has exactly n − 1 edges. Intuitively, you need at least n − 1 edges to connect n vertices (less and the graph disconnects), and adding one more creates a cycle. Trees are the "just barely connected" structures.

The no-cycle condition has a powerful consequence: there is exactly one path between any two vertices in a tree. If there were two distinct paths from u to v, following one forward and the other backward would form a cycle — contradicting the acyclic requirement. This uniqueness is what makes trees so useful in computer science: directory structures, parse trees, and search algorithms all exploit the fact that there is one canonical route between any two nodes.

A forest is simply a graph whose connected components are each trees — a disjoint union of trees. If a forest has n vertices and k connected components, it has exactly n − k edges. A forest with k = 1 component is a tree. This generalizes the tree edge count neatly.

A spanning tree of a connected graph G is a subgraph that (1) contains all vertices of G and (2) is itself a tree. You build a spanning tree by discarding edges while keeping the graph connected — strip away edges one at a time, but never disconnect anything. Equivalently, a spanning tree is a minimal connected spanning subgraph. Most graphs have many spanning trees. The question of how many — counting spanning trees — leads directly to the Matrix Tree Theorem. The question of which spanning tree minimizes total edge weight leads to the minimum spanning tree algorithms (Kruskal's, Prim's) that you will study next.

Practice Questions 5 questions

Prerequisite Chain

Understanding Zero → The Number Zero → Counting to Five → Counting to 10 → Counting to 20 → Counting a Set of Objects Up to 20 → Cardinality: The Last Number Counted → Matching Numerals to Quantities → Subitizing Small Quantities → Addition Within 10 → Number Bonds to 10 → Addition Within 20 → Doubles and Near Doubles → Doubles Facts Within 10 → Near Doubles Facts Within 20 → Mental Math Strategies for Addition → Mental Math: Adding and Subtracting Tens → Addition Within 100 → Repeated Addition as Multiplication → Multiplication as Equal Groups → Multiplication: Arrays → Basic Multiplication Facts (0s, 1s, 2s, 5s, 10s) → Multiplication Facts Within 100 → Division as Equal Sharing → Division as Grouping (Measurement Division) → Division: Grouping (Repeated Subtraction) Model → Division: Fair Sharing Model → Division as Equal Sharing → Division as Grouping → Basic Division Facts → Division Facts Within 100 → Multiplication and Division Fact Families → Relationship Between Multiplication and Division → Division Facts as Inverse of Multiplication → Remainders and Quotients in Division → Division Word Problems → Multi-Step Word Problems → Solving Multi-Step Word Problems → Multiplication Word Problems → Division Word Problems → Introduction to Long Division → Factors and Multiples → Prime and Composite Numbers → Equivalent Fractions → Relating Fractions and Decimals → Decimal Place Value → Integers and the Number Line → Comparing and Ordering Integers → Absolute Value → Adding Integers → Subtracting Integers → Multiplying Integers → Introduction to Exponents → Order of Operations → Integer Order of Operations → Variable Expressions → The Distributive Property → Variables and Expressions Review → Introduction to Polynomials → Adding and Subtracting Polynomials → Multiplying Polynomials → Factorial → Permutations → Combinations → Counting Principles: Addition and Multiplication Rules → Introduction to Graph Theory → Propositional Logic Foundations → Logical Equivalences → Set Operations: Union, Intersection, and Complement → Proof by Cases → Proving by Cases and Exhaustion → Vacuous Truth and Trivial Cases → Proof by Cases (Proof by Exhaustion) → Mathematical Induction → Graph Paths, Cycles, and Connectivity → Trees and Spanning Trees → Planar Graphs and Euler's Formula → Graph Coloring and the Chromatic Number → Graph Coloring and Chromatic Numbers → Bipartite Graphs and Matching Problems → Bipartite Graphs and 2-Colorability → Graph Matching and Hall's Marriage Theorem → Network Flows: Maximum Flow and Minimum Cut → Trees, Forests, and Spanning Trees

Longest path: 84 steps · 401 total prerequisite topics

Prerequisites (4)

Leads To (1)