Prim's Minimal Spanning Tree SWATHI
Prim's Minimal Spanning Tree SWATHI
PRESENTED BY:
K.SWATHI SUMANA
228R1A6230
INTRODUCTION
To execute the prim’s algorithm, the inputs taken by the algorithm are the graph G {V, E},
where V is the set of vertices and E is the set of edges, and the source vertex S. A minimum
spanning tree of graph G is obtained as an output.
Algorithm
• Declare an array visited[] to store the visited vertices and firstly, add the arbitrary root,
say S, to the visited array.
• Check whether the adjacent vertices of the last visited vertex are present in the visited[]
array or not.
• If the vertices are not in the visited[] array, compare the cost of edges and add the least
cost edge to the output spanning tree.
• The adjacent unvisited vertex with the least cost edge is added into the visited[] array
and the least cost edge is added to the minimum spanning tree output.
• Steps 2 and 4 are repeated for all the unvisited vertices in the graph to obtain the full
minimum spanning tree output for the given graph.
• Calculate the cost of the minimum spanning tree obtained.
EXAMPLE
Step 4
V = {S, B, A, E, D}
Step 5
V = {S, B, A, E, D, C}