Given a weighted connected undirected graph with node set V and edge set E, a subgraph of is called a spanning tree of if , , and . called a minimal spanning tree (MST) of if is a spanning tree of with the minimal total weight. Below is the Prim's MST algorithm to output the MST of a given graph .
Algorithm: Prim's MST algorithm Input: A weighted connected undirected graph , where Output: The MST with the minimal total weight, where
1: 2: , where w is an arbitrary node in V 3: while do 4: select an edge with the minimal weight such that and 5: 6: 7: return
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.