Minimum spanning tree algorithm