Minimum Spanning Trees: Prim's MST Algorithm
Minimum Spanning Trees: Prim's MST Algorithm
Spanning Trees
3
4 2
Tim Roughgarden
Prim’s MST Algorithm
- Initialize X = {s} [s ∈ V chosen arbitrarily]
- T = ∅ [invariant: X = vertices spanned by tree-so-far T ]
- While X 6= V
- Let e = (u, v ) be the cheapest edge of G with u ∈ X , v ∈
/ X.
- Add e to T
- Add v to X .
Tim Roughgarden
Correctness of Prim’s Algorithm
Theorem: Prim’s algorithm always computes an MST.
Tim Roughgarden