When should I use Kruskal as opposed to Prim (and vice versa)?

后端 未结 10 1369
小鲜肉
小鲜肉 2020-12-04 04:27

I was wondering when one should use Prim\'s algorithm and when Kruskal\'s to find the minimum spanning tree? They both have easy logics, same worst cases, and only differenc

10条回答
  •  抹茶落季
    2020-12-04 05:12

    One important application of Kruskal's algorithm is in single link clustering.

    Consider n vertices and you have a complete graph.To obtain a k clusters of those n points.Run Kruskal's algorithm over the first n-(k-1) edges of the sorted set of edges.You obtain k-cluster of the graph with maximum spacing.

提交回复
热议问题