Spanning Trees &
Minimum Spanning Trees
Discover how to connect every vertex of a graph with the fewest edges and the lowest total weight: the foundation of network optimization.
What Is a Graph?
A graph \( G = (V, E) \) consists of a set of vertices \( V \) (nodes) and a set of edges \( E \) (connections between nodes). Graphs model real-world networks: cities connected by roads, computers on a network, or circuit boards.
What Is a Tree?
A tree is a connected graph with no cycles. It is the simplest way to connect all vertices: removing any edge disconnects it, and adding any edge creates a cycle.
What Is a Spanning Tree?
A spanning tree of a connected graph \( G \) is a subgraph that includes all vertices of \( G \) and is itself a tree. It "spans" every vertex using exactly \( |V| - 1 \) edges, with no cycles.
Why Do Spanning Trees Matter?
Spanning trees appear everywhere in optimization. Whenever you need to connect all nodes at minimum cost, you need a spanning tree: network cabling, road planning, circuit design, and clustering algorithms all rely on them.
Weighted Graphs
A weighted graph assigns a numerical weight (cost, distance, time) to each edge. The total weight of a subgraph is the sum of all its edge weights:
Minimum Spanning Tree: Definition
The Cut Property
The cut property is the key theorem that justifies greedy MST algorithms. It guarantees that the lightest edge crossing any cut belongs to some MST.
Spanning Tree vs. MST
| Spanning Tree | Minimum Spanning Tree | |
|---|---|---|
| Vertices | All \( |V| \) | All \( |V| \) |
| Edges | \( |V| - 1 \) | \( |V| - 1 \) |
| Cycles | None | None |
| Weight Requirement | No constraint | Minimum possible |
| Uniqueness | Many possible | May not be unique |
| Needs Weights? | No | Yes |
Kruskal's Algorithm
Kruskal's algorithm builds an MST by greedily adding the lightest available edge that does not create a cycle. It processes edges in order of increasing weight.
Prim's Algorithm
Prim's algorithm grows an MST from a single starting vertex, always adding the cheapest edge that connects the growing tree to a vertex not yet included.
Example 1: The Graph
Find the MST of this weighted graph with 6 vertices and 9 edges.
Example 1: Kruskal's Solution
Sorted edges: CF:1, EF:2, BF:3, AB:4, DE:5, AD:6, BE:7, BC:8, AE:9. We add each if no cycle forms.
Example 2: Prim's on a 4-Vertex Graph
Example 3: Tie-Breaking
When multiple edges have the same weight, either can be chosen. This may produce different MSTs with the same total weight.
Common Mistakes
Kruskal's vs. Prim's
| Kruskal's | Prim's | |
|---|---|---|
| Strategy | Edge-centric (global sort) | Vertex-centric (grow from one node) |
| Data Structure | Union-Find | Priority Queue |
| Time Complexity | \( O(E \log E) \) | \( O(E \log V) \) |
| Best For | Sparse graphs | Dense graphs |
| Output | Same MST (or equal-weight MST) | Same MST (or equal-weight MST) |
Question 1 of 5
A connected graph has 8 vertices. How many edges does any spanning tree of this graph have?
Question 2 of 5
In Kruskal's algorithm, which edge is considered first?
Question 3 of 5
You are running Kruskal's algorithm. You pick the next lightest edge, but both its endpoints are already in the same connected component. What do you do?
Question 4 of 5
A graph has vertices {A, B, C, D} with edges AB:2, BC:3, CD:1, AD:4, BD:5. What is the total weight of the MST?
Question 5 of 5
Which statement about the cut property is correct?