Minimum
Spanning Tree
Using
Prims’s Algorithm
Design & Analysis
of Algorithm
Greedy Technique
Algorithm Design
Technique :
Problem :
Prim's Algorithm
Name: Mrunal Sanjay Patil
Roll No: 64
Year: FYMCA
 Greedy Method
• Greedy Method finds out of many options, but you have to choose
the best option.
• In this method we focused on the first stage and decide the output.
 Minimum Spanning Tree
A connected subgraph ‘M’ of graph G(V,E) is said to be spanning
Iff,
 ‘M’ should contain all vertices of ‘G’.
 ‘M’ should contain (|V|-1) edges.
𝑉1
𝑉2 𝑉3
𝑉4
𝐸1
𝐸2 𝐸4
𝐸3
Connected
Graph
Spanning Trees
𝑉1
𝑉2 𝑉3
𝑉4
𝐸1
𝐸2 𝐸4
𝐸3
 Minimum Cost Spanning Tree
• The cost of the spanning tree is the sum of the weights of all
the edges in the tree.
• Minimum spanning tree is the spanning tree where the cost is
minimum among all the spanning trees.
Undirected
Graph
4
1
3 2
5
A B
C D
Spanning Tree
Cost = 4+5+2
= 11
4
1
3 2
5
A B
C D
Minimum Cost Spanning Tree
Cost = 4+1+2
= 7
1
4 3 2
5
A B
C D
 We can find the minimum cost spanning
tree using 2 methods:
Prim’s Algorithms
Kruskal’s Algorithms
 Prim’s Algorithms
• Prim’s algorithm is a famous greedy algorithm.
• It is used for finding the Minimum Spanning Tree of a given graph.
• To apply prims algorithm, the given graph must be weighted,
connected and undirected.
 Explanation :
B
A
C
G
F
H
I
D
1
E
5 10
6
7
6
3
2
8
12
3
7
8
B
A D
1
5
C
F
3
2
E
7
H
8
G
7
I
3
Minimum Cost Spanning Tree
= Sum of all edge weight
 Cost of Minimum Spanning Tree
= 1 + 5 + 2 + 3 + 7 + 8 + 7 + 3
= 36
Program
If the input graph is presented using adjacency list , then the
time complexity of Prim’s algorithm can be reduced to O(E log V)
with the help of binary heap.
Time Complexity of the above program is
O( )
𝑉2
Thank You…

Minimum Spanning Tree Using Prism's Algorithm

  • 1.
  • 2.
    Design & Analysis ofAlgorithm Greedy Technique Algorithm Design Technique : Problem : Prim's Algorithm Name: Mrunal Sanjay Patil Roll No: 64 Year: FYMCA
  • 3.
     Greedy Method •Greedy Method finds out of many options, but you have to choose the best option. • In this method we focused on the first stage and decide the output.
  • 4.
     Minimum SpanningTree A connected subgraph ‘M’ of graph G(V,E) is said to be spanning Iff,  ‘M’ should contain all vertices of ‘G’.  ‘M’ should contain (|V|-1) edges. 𝑉1 𝑉2 𝑉3 𝑉4 𝐸1 𝐸2 𝐸4 𝐸3
  • 5.
  • 6.
     Minimum CostSpanning Tree • The cost of the spanning tree is the sum of the weights of all the edges in the tree. • Minimum spanning tree is the spanning tree where the cost is minimum among all the spanning trees. Undirected Graph 4 1 3 2 5 A B C D Spanning Tree Cost = 4+5+2 = 11 4 1 3 2 5 A B C D Minimum Cost Spanning Tree Cost = 4+1+2 = 7 1 4 3 2 5 A B C D
  • 7.
     We canfind the minimum cost spanning tree using 2 methods: Prim’s Algorithms Kruskal’s Algorithms
  • 8.
     Prim’s Algorithms •Prim’s algorithm is a famous greedy algorithm. • It is used for finding the Minimum Spanning Tree of a given graph. • To apply prims algorithm, the given graph must be weighted, connected and undirected.
  • 9.
  • 10.
  • 11.
    = Sum ofall edge weight  Cost of Minimum Spanning Tree = 1 + 5 + 2 + 3 + 7 + 8 + 7 + 3 = 36
  • 13.
  • 14.
    If the inputgraph is presented using adjacency list , then the time complexity of Prim’s algorithm can be reduced to O(E log V) with the help of binary heap. Time Complexity of the above program is O( ) 𝑉2
  • 15.