Education
 

Proof of Prim's algorithm

From Mathematics

Prim's algorithm yields a minimal spanning tree.

[edit] Proof

Let math be the spanning tree on math generated by Prim's algorithm, which must be proved to be minimal, and let math be spanning tree on math, which is known to be minimal.

If math, then math is minimal.

If math, let math be the first edge chosen by Prim's algorithm which is not in math, chosen on the math'th iteration of Prim's algorithm. Let math be the path from math to math in math, and let math be an edge in math such that one endpoint is in the tree generated at the math'th iteration of Prim's algorithm and the other is not, i.e., one endpoint of math is math or one endpoint is math, but the endpoints are not math and math.

If the weight of math is less than the weight of math, then Prim's algorithm would have chosen it on its mathth iteration, so it is certain that math. In particular, when math has weight equal to that of math, the choice between the two is arbitrary. Whether the weight of math is greater than or equal to math, math can be substituted with math while preserving minimal total weight of math. This process can be repeated indefinitely, until math is equal to math, and it is shown that the tree generated by any instance of Prim's algorithm is a minimal spanning tree.

QED