01 / 20

Minimum
Spanning Trees

Learn how to find the cheapest way to connect every node in a network: the foundation of efficient graph optimization.

Finite Mathematics

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.

\(4\)
\(6\)
\(3\)
\(5\)
\(8\)
\(7\)
\(2\)
A B C D E

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.

Connected
There is a path between every pair of vertices
No Cycles
Removing any edge disconnects the tree
\( n - 1 \) Edges
Exactly the minimum number of edges to stay connected

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?"

Network Design
Lay cables, pipes, or roads between cities at minimum cost
Clustering
Remove the longest MST edges to separate data into groups
Approximation
MSTs help estimate solutions to harder problems like the Traveling Salesman

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

1
List all edges and sort them by weight from smallest to largest.
2
Pick the smallest edge. If adding it does not create a cycle, include it in the MST.
3
Repeat with the next smallest edge until you have \( n - 1 \) edges.
4
Sum the weights of the selected edges to get the MST total weight.

Example 1: The Graph

Find the MST of this weighted graph using Kruskal's algorithm.

\(4\)
\(6\)
\(9\)
\(3\)
\(5\)
\(7\)
\(8\)
\(2\)
A B C D E

Example 1: Building the MST

\(2\)
\(3\)
\(4\)
\(5\)
A B C D E
1
D-E (\(2\)): No cycle. Accept ✓
2
B-C (\(3\)): No cycle. Accept ✓
3
A-B (\(4\)): No cycle. Accept ✓
4
B-D (\(5\)): No cycle. Accept ✓ Now \( n - 1 = 4 \) edges. Done!

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.

\(1\)
\(4\)
\(3\)
\(5\)
\(6\)
\(2\)
P Q R S

Example 2: Solution

\(1\)
\(2\)
\(3\)
P Q R S
1
P-Q (\(1\)): No cycle. Accept ✓
2
Q-R (\(2\)): No cycle. Accept ✓
3
Q-S (\(3\)): No cycle. Accept ✓ We have \( 4 - 1 = 3 \) edges. Done!

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.

1
Start at A. Cheapest edge from A: A-B (\(4\)). Tree: {A, B}.
2
From {A, B}: cheapest to a new vertex: B-C (\(3\)). Tree: {A, B, C}.
3
From {A, B, C}: cheapest to a new vertex: B-D (\(5\)). Tree: {A, B, C, D}.
4
From {A, B, C, D}: cheapest to a new vertex: D-E (\(2\)). Tree: {A, B, C, D, E}.

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.

Unique MST
All edge weights are distinct: exactly one MST exists
Non-Unique MST
Some edges share weights: multiple MSTs may exist with the same total

Key MST Properties

\( n - 1 \) Edges
An MST of \( n \) vertices always has exactly \( n - 1 \) edges
No Cycles
Adding any non-tree edge creates exactly one cycle
Connected
Removing any tree edge disconnects the tree into exactly two components

Common Mistakes

✕ Forgetting the Cycle Check
Adding a cheap edge that creates a cycle means it is no longer a tree. Always verify before including an edge.
✕ Stopping Too Early or Late
An MST needs exactly \( n - 1 \) edges. Fewer means the graph is disconnected; more means it has a cycle.
✕ Confusing MST with Shortest Path
MST minimizes total connection cost, not the distance between any two specific vertices. Those are different problems.

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?