Prim's algorithm is a greedy algorithm that finds a minimum spanning tree for a connected, weighted graph. The algorithm starts at an arbitrary node adding the cheapest possible connection from the tree to another non-tree vertex at every step.
The algorithm performs the following steps: