0% found this document useful (0 votes)
0 views

Prim’s Algorithm (1)

Prim's Algorithm is a greedy method for finding the minimum spanning tree of a graph by selecting edges with the smallest weights without forming cycles. The algorithm starts from a chosen vertex and iteratively adds the minimum weight edge connecting the tree to a new vertex until the spanning tree is complete. Applications include network design and electrical wiring layout.

Uploaded by

SAYALI TARARE
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Prim’s Algorithm (1)

Prim's Algorithm is a greedy method for finding the minimum spanning tree of a graph by selecting edges with the smallest weights without forming cycles. The algorithm starts from a chosen vertex and iteratively adds the minimum weight edge connecting the tree to a new vertex until the spanning tree is complete. Applications include network design and electrical wiring layout.

Uploaded by

SAYALI TARARE
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

PRIM’S ALGORITHM

PRESENTED BY:-
 ANISHA DHUMAL
 SAYALI TARARE
 JINAL LADDHA
INTRODUCTION
• Prim's Algorithm is a greedy algorithm that is used to find the
minimum spanning tree from a graph. Prim's algorithm finds the
subset of edges that includes every vertex of the graph such
that the sum of the weights of the edges can be minimized.
• Prim's algorithm starts with the single node and explores all the
adjacent nodes with all the connecting edges at every step. The
edges with the minimal weights causing no cycles in the graph
got selected.
BASIC CONCEPTS
• Spanning tree - A spanning tree is the subgraph of an
undirected connected graph.
• Minimum Spanning tree - Minimum spanning tree can
be defined as the spanning tree in which the sum of the
weights of the edge is minimum. The weight of the
spanning tree is the sum of the weights given to the edges
of the spanning tree.
How does the Prim’s Algorithm work?

• Prim's algorithm is a greedy algorithm that starts from one vertex


and continue to add the edges with the smallest weight until the
goal is reached. The steps to implement the prim's algorithm are
given as follows -
• First, we have to initialize an MST with the randomly chosen vertex.
• Now, we have to find all the edges that connect the tree in the
above step with the new vertices. From the edges found, select the
minimum edge and add it to the tree.
• Repeat step 2 until the minimum spanning tree is formed.
The Applications of Prim’s
Algorithm:-

• Prim's algorithm can be used in network designing.


• It can be used to make network cycles.
• It can also be used to lay down electrical wiring cables.
Example of Prim’s Algorithm

 Suppose, a weighted graph is -


 Step 1 - First, we have to choose a vertex from the above
graph. Let's choose B.

 Step 2 - Now, we have to choose and add the shortest edge from
vertex B. There are two edges from vertex B that are B to C with
weight 10 and edge B to D with weight 4. Among the edges, the
edge BD has the minimum weight. So, add it to the MST
 Step 3 - Now, again, choose the edge with the minimum weight
among all the other edges. In this case, the edges DE and CD are
such edges. Add them to MST and explore the adjacent of C, i.e., E
and A. So, select the edge DE and add it to the MST.

 Step 4 - Now, select the edge CD, and add it to the


MST.
Step 5 - Now, choose the edge CA. Here, we cannot select the edge
CE as it would create a cycle to the graph. So, choose the edge CA
and add it to the MST.

So, the graph produced in step 5 is the minimum spanning tree of the
given graph. The cost of the MST is given below -

Cost of MST = 4 + 2 + 1 + 3 = 10
units.
Algorithm
 Step 1: Select a starting vertex
 Step 2: Repeat Steps 3 and 4 until there are fringe vertices
 Step 3: Select an edge 'e' connecting the tree vertex and fringe vertex
that has minimum weight
 Step 4:
Add the selected edge and the vertex to the minimum spanning tree T

 [END OF LOOP]
 Step 5: EXIT

You might also like