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 moreMinimum 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 ZeroThe Number ZeroCounting to FiveCounting to 10Counting to 20Counting a Set of Objects Up to 20Cardinality: The Last Number CountedMatching Numerals to QuantitiesSubitizing Small QuantitiesAddition Within 10Number Bonds to 10Addition Within 20Doubles and Near DoublesDoubles Facts Within 10Near Doubles Facts Within 20Mental Math Strategies for AdditionMental Math: Adding and Subtracting TensAddition Within 100Repeated Addition as MultiplicationMultiplication as Equal GroupsMultiplication: ArraysBasic Multiplication Facts (0s, 1s, 2s, 5s, 10s)Multiplication Facts Within 100Division as Equal SharingDivision as Grouping (Measurement Division)Division: Grouping (Repeated Subtraction) ModelDivision: Fair Sharing ModelDivision as Equal SharingDivision as GroupingBasic Division FactsDivision Facts Within 100Multiplication and Division Fact FamiliesRelationship Between Multiplication and DivisionDivision Facts as Inverse of MultiplicationRemainders and Quotients in DivisionDivision Word ProblemsMulti-Step Word ProblemsSolving Multi-Step Word ProblemsMultiplication Word ProblemsDivision Word ProblemsIntroduction to Long DivisionFactors and MultiplesPrime and Composite NumbersEquivalent FractionsRelating Fractions and DecimalsDecimal Place ValueIntegers and the Number LineComparing and Ordering IntegersAbsolute ValueAdding IntegersSubtracting IntegersMultiplying IntegersIntroduction to ExponentsOrder of OperationsInteger Order of OperationsVariable ExpressionsThe Distributive PropertyVariables and Expressions ReviewIntroduction to PolynomialsAdding and Subtracting PolynomialsMultiplying PolynomialsFactorialPermutationsCombinationsCounting Principles: Addition and Multiplication RulesIntroduction to Graph TheoryPropositional Logic FoundationsLogical EquivalencesSet Operations: Union, Intersection, and ComplementProof by CasesProving by Cases and ExhaustionVacuous Truth and Trivial CasesProof by Cases (Proof by Exhaustion)Mathematical InductionGraph Paths, Cycles, and ConnectivityTrees and Spanning TreesPlanar Graphs and Euler's FormulaGraph Coloring and the Chromatic NumberGraph Coloring and Chromatic NumbersBipartite Graphs and Matching ProblemsBipartite Graphs and 2-ColorabilityGraph Matching and Hall's Marriage TheoremNetwork Flows: Maximum Flow and Minimum CutTrees, Forests, and Spanning Trees

Longest path: 84 steps · 401 total prerequisite topics

Prerequisites (4)

Leads To (1)