演算法›Ch4 圖論演算法
第 108 題/共 111 題
◀ AL 108/111
108. Minimum Spanning Tree、Kruskal's Algorithm、Prim's Algorithm
#AL-04-108中Minimum Spanning TreeKruskal's AlgorithmPrim's Algorithm

Given a weighted connected undirected graph G=(V,E)G=(V, E) with node set V and edge set E, a subgraph MM of GG is called a spanning tree of GG if M=(V,T)M = (V, T), T⊆ET \subseteq E, and ∣T∣=∣V∣−1|T|=|V|-1. MM called a minimal spanning tree (MST) of GG if MM is a spanning tree of GG with the minimal total weight. Below is the Prim's MST algorithm to output the MST of a given graph GG.

Algorithm: Prim's MST algorithm Input: A weighted connected undirected graph G=(V,E)G=(V, E), where ∣V∣=n|V|=n Output: The MST M=(V,T)M=(V, T) with the minimal total weight, where ∣T∣=n−1|T|=n-1

1: T←ϕT \leftarrow \phi 2: X←{w}X \leftarrow \{w\}, where w is an arbitrary node in V 3: while ∣T∣<n−1|T| < n-1 do 4: select an edge (u,v)∈E(u, v) \in E with the minimal weight such that u∈Xu \in X and v∈(V−X)v \in (V-X) 5: T←T∪{(u,v)}T \leftarrow T \cup \{(u, v)\} 6: X←X∪{v}X \leftarrow X \cup \{v\} 7: return M=(V,T)M=(V, T)

Please follow the form of the Prim's MST algorithm to (1) write the well-known Kruskal's MST algorithm (9%) and (2) analyze the worst-case time complexity of the Kruskal's MST algorithm (6%). Note that you should strictly follow the form of the Prim's MST algorithm to write the Kruskal's MST algorithm; otherwise, you will lose some points.

📄 中央111
跳轉到第題
▤完整推導請見《WH 資工筆記 · 演算法》Ch4 圖論演算法
本章題號 · 101–111 / 111