Kruskal's algorithm