MST

最小生成树是图的一个子集,满足包含图的所有节点(V),但是只有V-1条边

  • 如果本身图不联通,无法找到MST

Prims

先找到最小的边,然后always select min which is connected O(ne) or O(nn)

Kruskal's

always select min cost edge, but if it forms a cycle, dont include it in the solution

  • 这个算法就可以用min heap,这就不需要再search,所以复杂度可以降到O(nlogn)
  • 而如何判断是否构成cycle就是通过Union Find 理解

results matching ""

    No results matching ""