PRIM’S ALGORITHM
PRESENTED BY –> Siddhartha Pradhan
Course – Computer Science Honours
2nd Semester
Roll No - 3154
Introduction to PRIM’S ALGORITHM
• Prim’s algorithm is used to find the Minimum Spanning
Tree(MST) for a given graph.
• The algorithm was discovered in 1930 by mathematician
Vojtech Jamik and later independently by computer scientist
Robert C. Prim in 1957.
• The algorithm continuously increases the size of a tree
starting with a single vertex until it spans all the vertices.
• This algorithm finds the subset of edges for graph G(V,E) such
that the summation of edge weights is minimum.
• Prim’s algorithm is a Greedy algorithm.
MINIMUM COST SPANNING TREE
• A Minimum Spanning Tree(MST) Prim’s Algorithm
is a subgraph of an undirected
graph such that the subgraph 1. Select any vertex.
spans(includes) all nodes, is
connected, is acyclic, and has 2. Select the shortest
minimum total edge weight edge connected to
that vertex.
3. Select the shortest
edge connected to
any vertex already
connected
4. Repeat step 3 until all
vertices have been
A graph and spanning tree connected
Finding MST with PRIM’S Algorithm
Finding MST with Prim’s Algorithm
We need to find Minimum Spanning Tree G’(V’,E’) for the given
graph G(V,E) such that the sum of edge weights is minimized.
Finding MST with Prim’s Algorithm
STEP: 1 – Choose an arbitrary starting Vertex. STEP: 2 – Keep including connected edges
Here, we will begin with vertex A with minimal cost.
We will choose B as edge AB has
minimum edge weight.
Finding MST with Prim’s Algorithm
We must consider all the edges that are visible from all
the already discovered vertices. From vertex B we will
choose vertex C as it has minimum cost .
Finding MST with Prim’s Algorithm
Now, from vertex C we will choose
vertex E as it has the minimum From vertex E, we will choose vertex D
cost compared to edge CG ,CD, AI. because it has smaller weight.
Finding MST with Prim’s Algorithm
STEP 3 – Make sure that there is no loop in tree structure.
To avoid loop we will move to the G vertex and also edge CG
has the smallest weight compared to edge DF and AI.
Finding MST with Prim’s Algorithm
From vertex G we will choose edge GF as it has the least
cost compared to the other edges.
Finding MST with Prim’s Algorithm
According to the Prim’s Algorithm, now we must consider edges
AI, FH and GI. Since GI is the smallest edge, we will choose it
next.
Finding MST with Prim’s Algorithm
Finally, vertex H can be accessed via edge FH or IH . Since
edge IH is smaller, we will choose it.
The minimum spanning tree has been found . The order of vertex discovery is as
follows:
A,B,C,E,D,G, F,I ,H
So,
The cost for this MST G’(V’,E’) is = Summation of all the edge weights of MST
= 7 +5+2+1+3+5+6+10
Hence, the Minimum Cost of Spanning Tree is 39.