Builds a minimum spanning tree by sorting edges by weight and adding each edge that does not create a cycle.
make-set(v) for each v; MST = ∅sort edges by nondecreasing weightfor each edge (u,v) in sorted order:if find(u) ≠ find(v):union(u,v); add (u,v) to MSTreturn MST