Implementing a minimum spanning tree using a greedy algorithm