Prim’s Algorithm (1)
Prim’s Algorithm (1)
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?
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.
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