0% found this document useful (0 votes)
8 views

Minimum Spanning Trees: Prim's MST Algorithm

Uploaded by

sirj0_hn
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Minimum Spanning Trees: Prim's MST Algorithm

Uploaded by

sirj0_hn
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Minimum

Spanning Trees

Prim’s MST Algorithm


Algorithms: Design
and Analysis, Part II
Example
[Purple edges = minimum spanning tree]
(Compare to Dijkstra’s shortest-path algorithm)

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 .

While loop: Increase # of spanned vertices in cheapest way


possible.

Tim Roughgarden
Correctness of Prim’s Algorithm
Theorem: Prim’s algorithm always computes an MST.

Part I: Computes a spanning tree T ∗ .


[Will use basic properties of graphs and spanning trees] (Useful
also in Kruskal’s MST algorithm)

Part II: T ∗ is an MST.


[Will use the “Cut Property”] (Useful also in Kruskal’s MST
algorithm)

Later: Fast [O(m log n)] implementation using heaps.

Tim Roughgarden

You might also like