The algorithm to determine the minimum spanning tree given in this chapter is of the order O(n3). The following is an alternative to Prim’s algorithm that is of the order O(n2).Input: A connected weighted graph G = (V, E) of n vertices, numbered 0, 1, …, n − 1; starting with vertex s, with a weight matrix of W.
Output: The minimum spanning tree.
Prim2(G, W, n, s)
Let T = (V, E), where E = ϕ.
for(j = 0; j
@@{edgeWeight [ j ] = W(s,j);
edges[j ] = s;
visited[s] = false;}
edgeWeight[s] = 0; visited[s] = true;
while(not all nodes are visited)
{Choose the node that is not visited and has the smallest weight, and call it k.
visited[ k] = true;
E = E ∪{(k, edges[k])}
V = V ∪{k}
for each node j that is not visited if(W(k, j)
{edgeWeight [k] =W(k,j); edges[j] = k;}}
return T.##
Write a definition of the function Prim2 to implement this algorithm, and also add this function to the class msTreeType. Furthermore, write a program to test this version of Prim’s algorithm.
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.