Prim's Algorithm
- Explain how to implement Prim's algorithm.
A Greedy algorithm that grows an MST from a starting source vertex until it spans the entire graph:
- Start with an empty minimum spanning tree .
- Pick a vertex (at random) and add it to .
- Choose a vertex not in , such that the edge weight from a vertex in to is the least among all such edges.
- Add to .
- Repeat the last two steps until edges were added.
Demo
Resources
- Wikipedia's entry on Prim's Algorithm.
- Interactive visualization of Prim's Algorithm by Reza Sefidgar.