0% found this document useful (0 votes)
19 views6 pages

Prim's Minimal Spanning Tree SWATHI

Uploaded by

swathisumana.k
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views6 pages

Prim's Minimal Spanning Tree SWATHI

Uploaded by

swathisumana.k
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 6

PRIM’S MINIMAL SPANNING TREE

PRESENTED BY:
K.SWATHI SUMANA
228R1A6230
INTRODUCTION

Prim’s minimal spanning tree algorithm is one of the efficient


methods to find the minimum spanning tree of a graph. A
minimum spanning tree is a sub graph that connects all the
vertices present in the main graph with the least possible edges
and minimum cost (sum of the weights assigned to each edge).
The algorithm, similar to any shortest path algorithm, begins
from a vertex that is set as a root and walks through all the
vertices in the graph by determining the least cost adjacent
edges.
PRIM’S ALGORITHM

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

Find the minimum spanning tree using prim’s method (greedy


approach) for the graph given below with S as the arbitrary root.
Step 1
Create a visited array to store all the visited vertices into it.
V={ }

The arbitrary root is mentioned to be S, so among all the edges


that are connected to S we need to find the least cost edge.
S→B=8
V = {S, B}
Step 2
V = {S, B, A}
Step 3
V = {S, B, A, E}

Step 4
V = {S, B, A, E, D}

Step 5
V = {S, B, A, E, D, C}

The minimum spanning tree is obtained with the minimum cost


= 46
THANK YOU

You might also like