Pseudocode
The following code is implemented with disjoint-set data structure:
foreach v ∈ V:
MAKE_SET(v)
G.E = sort(G.E)
i = 0
while (i != |V|-1):
pick the next (u, v) edge from sorted list of edges G.E
if (FIND_SET(u) != FIND_SET(v)):
UNION(u, v)
i = i + 1
Read more about this topic: Kruskal's Algorithm