Prim's Minimum Spanning Tree

Vojtěch Jarník & Robert Prim, 1930

O(E log V)

Originally discovered by Vojtěch Jarník in 1930 and independently rediscovered by Robert Prim in 1957, this greedy algorithm grows a minimum spanning tree one edge at a time. Starting from an arbitrary node, it repeatedly selects the lowest-weight edge that connects a tree node to a non-tree node, absorbing the new node into the MST. The visualization shows MST edges in teal, the candidate edge being considered in gold, and nodes changing color as they join the tree.