DSA Notes
Master Minimum Spanning Tree concepts completely — what an MST is, the cut property and cycle property proofs, why MSTs are optimal, the two fundamental MST algorithms (Kruskal
What Is a Spanning Tree?
A spanning tree of a connected undirected graph G = (V, E) is a subgraph T = (V, E') that:
- Contains all vertices of G
- Is a tree (connected, no cycles)
- Has exactly V-1 edges
A spanning tree spans (covers) all vertices while using the minimum possible edges.
MST Properties
Property 1: Cut Property
A cut is a partition of vertices into two non-empty groups S and V-S. Crossing edges cross between S and V-S.
Cut Property: For any cut (S, V-S), the minimum-weight crossing edge belongs to some MST.
This property is the foundation of both Kruskal's and Prim's algorithms.
Property 2: Cycle Property
For any cycle in G, the maximum-weight edge in the cycle does NOT belong to any MST (if all edge weights are distinct).
Intuition: If we have a cycle, we can always remove the heaviest edge without disconnecting the graph, reducing total weight. So the heaviest cycle edge is never in the MST.
MST Algorithms Summary
| Algorithm | Strategy | Time | Best For |
|---|---|---|---|
| Kruskal's | Add cheapest edge not forming cycle | O(E log E) | Sparse graphs |
| Prim's | Add cheapest edge extending MST | O(E log V) | Dense graphs |
| Borůvka's | Each component adds cheapest outgoing edge | O(E log V) | Parallel computation |
Building MSTs — Quick Preview
Kruskal's (Sort + DSU)
| Sort all edges by weight | [(1,D-C),(2,A-D),(3,B-C),(4,A-B)] |
| Add D-C (weight 1) | {D-C} |
| Add A-D (weight 2) | {D-C, A-D} |
| Add B-C (weight 3) | {D-C, A-D, B-C} |
| Skip A-B (weight 4) | would create cycle A-D-C-B-A |
| MST | {D-C, A-D, B-C}, total weight = 6 ✓ |
Prim's (Priority Queue)
| Start with A | candidates = {A-D:2, A-B:4} |
| Add cheapest (A-D | 2): MST = {A-D}, candidates = {A-B:4, D-C:1} |
| Add cheapest (D-C | 1): MST = {A-D, D-C}, candidates = {A-B:4, C-B:3} |
| Add cheapest (C-B | 3): MST = {A-D, D-C, C-B} |
Real-World Applications
1. Network Design (Minimum Cost)
2. Cluster Analysis
3. Approximation Algorithms
4. Image Segmentation
5. VLSI Circuit Design
MST Uniqueness
An MST is unique if and only if all edge weights are distinct.
Proof
If all edges have distinct weights, the cut property uniquely determines
which edge must be included for each cut.
If some edges share weights
Multiple edges might tie for "minimum crossing edge" in a cut,
leading to different but equally-weight MSTs.
Example of non-unique MST
A—1—B—1—C
All edges weight 1.
MSTs: {A-B, B-C} and {A-B, A-C} and {B-C, A-C} ← three MSTs, same weight 2
Properties of MSTs
- An MST has exactly V-1 edges (tree property)
- Removing any edge from MST disconnects the graph (tree property)
- Adding any non-MST edge creates exactly one cycle (tree property)
- MST weight ≤ weight of any spanning tree (by definition)
- For unique weights: MST is unique (cut property uniqueness)
- MST is optimal for min-cost connection: MST always gives minimum total edge weight
Finding Maximum Spanning Tree
Maximum spanning tree (maximum total weight) uses the same algorithms — just negate all weights or sort in descending order:
Applications: Maximum bottleneck paths, maximum reliability networks.
Summary
A Minimum Spanning Tree connects all vertices with minimum total edge weight:
- V-1 edges (tree structure)
- Cut property: Minimum crossing edge for any cut ∈ some MST
- Cycle property: Maximum edge in any cycle ∉ any MST
- Algorithms: Kruskal's (sort+DSU), Prim's (priority queue)
- Time: O(E log E) for Kruskal's, O(E log V) for Prim's
- Uniqueness: Guaranteed only when all edge weights are distinct
*Next Lesson: Prim's Algorithm*
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Minimum Spanning Tree — Definition, Properties, and Applications.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Data Structures & Algorithms topic.
Search Terms
data-structures-algorithms, data structures & algorithms, data, structures, algorithms, graphs, minimum, spanning
Related Data Structures & Algorithms Topics