Minimum
Spanning Trees
Learn how to find the cheapest way to connect every node in a network: the foundation of efficient graph optimization.
What Is a Graph?
A graph is a collection of vertices (nodes) connected by edges (links). When each edge has a number called a weight, we call it a weighted graph. Weights often represent distance, cost, or time.
What Is a Spanning Tree?
A spanning tree of a connected graph is a subgraph that includes every vertex and is a tree: connected with no cycles. For a graph with \( n \) vertices, every spanning tree has exactly \( n - 1 \) edges.
Why Do MSTs Matter?
A Minimum Spanning Tree (MST) is the spanning tree whose total edge weight is as small as possible. It answers: "What is the cheapest way to connect everything?"
The Cut Property
The cut property guarantees that greedy algorithms find the MST. It states:
This means: at every step, if you pick the lightest edge that connects a new vertex to the tree, you are guaranteed to end up with an MST.
Kruskal's vs. Prim's
Two classic algorithms find the MST. Both are greedy and always produce the correct result, but they differ in strategy.
| Kruskal's | Prim's | |
|---|---|---|
| Strategy | Sort all edges by weight, add cheapest that doesn't create a cycle | Grow tree from a start vertex, always adding the cheapest edge to a new vertex |
| Works on | Edge list (good for sparse graphs) | Adjacency list (good for dense graphs) |
| Stops when | \( n - 1 \) edges added | All vertices included |
How to Apply Kruskal's Algorithm
Example 1: The Graph
Find the MST of this weighted graph using Kruskal's algorithm.
Example 1: Building the MST
Example 2: Cycle Detection
Sometimes, when building the MST, an edge must be rejected because it would form a cycle. Consider this 4-vertex graph.
Example 2: Solution
Example 3: Prim's Algorithm
Use Prim's algorithm starting from vertex A on the same graph from Example 1. At each step, add the cheapest edge from the tree to a vertex not yet in the tree.
Can an MST Be Non-Unique?
Yes! When two or more edges share the same weight, the graph may have multiple MSTs with the same total cost. Each is equally correct.
Key MST Properties
Common Mistakes
Question 1 of 5
A connected graph has 8 vertices. How many edges does its minimum spanning tree have?
Question 2 of 5
In Kruskal's algorithm, when should you reject an edge?
Question 3 of 5
A graph has 4 vertices and edges with weights 1, 2, 3, 4, 5, 6. Using Kruskal's, you accept edges of weight 1, 2, and 3. What is the total weight of the MST?
Question 4 of 5
Which statement about minimum spanning trees is true?
Question 5 of 5
In Prim's algorithm, what determines which edge to add next?