Prim's Algorithm
Summarized notes on Introduction to Algorithms, Chapter 23
- edges in set
always maintain a tree - start from arbitrary root vertex
and grow until tree spans all vertices in - during algorithm vertices not in
are in min-priority queue ordered by edge weight- after algorithm finishes queue is empty
- maintains 3 loop invariants
( is root)- vertices in MST are those in
- for all vertices in
, if then and is weight of a light edge connecting to some vertex already in MST
Example
Complexity
Running time | |
---|---|
Prim's using binary min-heap | |
Prim's using Fibonacci heap |