SlideShare a Scribd company logo
Spanning Subgraph
A subgraph of a graph, which contains all the vertices of the graph.
Spanning Tree
A spanning tree is a subgraph (spanning subgraph) of a graph, which contains all the vertices of
the graph and contains no cycle.
Minimum Cost Spanning Tree
It is a spanning tree whose cost is minimum. There are two well-known algorithms to build
minimum cost spanning tree. One is Prim’s algorithm and another is Kruskal’s algorithm.
Prim's Algorithm
Prim's algorithm is a minimum spanning tree algorithm that takes a graph as input and finds the
subset of the edges of that graph which
 form a tree that includes every vertex
 has the minimum sum of weights among all the trees that can be formed from the graph
The steps for implementing Prim's algorithm are as follows:
1. Initialize the minimum spanning tree with a vertex chosen at random.
2. Find all the edges that connect the tree to new vertices, find the minimum and add it to the tree
3. Keep repeating step 2 until we get a minimum spanning tree
Example
Construct the minimum spanning tree (MST) for the given graph using Prim’s Algorithm-
Solution:
Step-01 Step-02 Step-03 Step-04
Step-05 Step-06
Now, Cost of Minimum Spanning Tree
= Sum of all edge weights
= 10 + 25 + 22 + 12 + 16 + 14
= 99 units
Prim's Algorithm pseudocode
T = ∅;
U = { 1 };
while (U ≠ V)
let (u, v) be the lowest cost edge such that u ∈ U and v ∈ V
- U;
T = T ∪ {(u, v)}
U = U ∪ {v}
Kruskal's Algorithm
Kruskal's algorithm is a minimum spanning tree algorithm that takes a graph as input and finds
the subset of the edges of that graph which
 form a tree that includes every vertex
 has the minimum sum of weights among all the trees that can be formed from the graph
The steps for implementing Kruskal's algorithm are as follows:
1. Sort all the edges from low weight to high
2. Take the edge with the lowest weight and add it to the spanning tree. If adding the edge
created a cycle, then reject this edge.
3. Keep adding edges until we reach all vertices.
Example
Construct the minimum spanning tree (MST) for the given graph using Kruskal’s Algorithm-
Solution
Step-01 Step-02
Step-03 Step-04
Step-05 Step-06
Weight of the MST
= Sum of all edge weights
= 10 + 25 + 22 + 12 + 16 + 14
= 99 units
Kruskal Algorithm Pseudocode
KRUSKAL(G):
A = ∅
For each vertex v ∈ G.V:
MAKE-SET(v)
For each edge (u, v) ∈ G.E ordered by increasing order by
weight(u, v):
if FIND-SET(u) ≠ FIND-SET(v):
A = A ∪ {(u, v)}
UNION(u, v)
return A

More Related Content

Similar to MST (20)

PPTX
Data structure
SangeethaSasi1
 
PPTX
Data structure
kavitha muneeshwaran
 
PPTX
Minimum spanning tree
STEFFY D
 
PPT
ADA - Minimum Spanning Tree Prim Kruskal and Dijkstra
Sahil Kumar
 
PPTX
_A C program for Prim's Minimum Spanning Tree (MST) algorithm. The program is...
SatyamMishra828076
 
PPTX
11L_2024_DSCS_EN_Trees2_Prim_Kraskal.pptx
RavanGulmetov
 
PPT
Greedy Approach in Design Analysis and Algorithms
NikunjGoyal20
 
PDF
Ijciras1101
zhendy94
 
PPTX
Minimum Spanning Tree (Data Structure and Algorithm)
chandankumar364348
 
PPT
Minimum spanning tree
Hinal Lunagariya
 
PPT
Minimum Spanning Tree
Md. Shafiuzzaman Hira
 
PPT
Unit27_MinimumSpanningTree.ppt data structure programming
Arjunkrish9
 
PPTX
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
Madhu Bala
 
PPTX
APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...
KUSHDHIRRA2111026030
 
PDF
Minimum-Spanning-Tree.pdf ramswaroop memorial University
SatyamMishra828076
 
PPT
17 prims-kruskals (1)
MOHAMMADATHARKHAN2
 
PPTX
Minimum spanning tree
AhmedMalik74
 
PPTX
Minimum Spinning Tree Full Explaination pptx
TayyabArif8
 
PPTX
Presentation.pptx
rohitsingh935398
 
PPTX
Greedy Strategy.pptxbfasjbjfn asnfn anjn
eraqhuzay69
 
Data structure
SangeethaSasi1
 
Data structure
kavitha muneeshwaran
 
Minimum spanning tree
STEFFY D
 
ADA - Minimum Spanning Tree Prim Kruskal and Dijkstra
Sahil Kumar
 
_A C program for Prim's Minimum Spanning Tree (MST) algorithm. The program is...
SatyamMishra828076
 
11L_2024_DSCS_EN_Trees2_Prim_Kraskal.pptx
RavanGulmetov
 
Greedy Approach in Design Analysis and Algorithms
NikunjGoyal20
 
Ijciras1101
zhendy94
 
Minimum Spanning Tree (Data Structure and Algorithm)
chandankumar364348
 
Minimum spanning tree
Hinal Lunagariya
 
Minimum Spanning Tree
Md. Shafiuzzaman Hira
 
Unit27_MinimumSpanningTree.ppt data structure programming
Arjunkrish9
 
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
Madhu Bala
 
APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...
KUSHDHIRRA2111026030
 
Minimum-Spanning-Tree.pdf ramswaroop memorial University
SatyamMishra828076
 
17 prims-kruskals (1)
MOHAMMADATHARKHAN2
 
Minimum spanning tree
AhmedMalik74
 
Minimum Spinning Tree Full Explaination pptx
TayyabArif8
 
Presentation.pptx
rohitsingh935398
 
Greedy Strategy.pptxbfasjbjfn asnfn anjn
eraqhuzay69
 

More from A. S. M. Shafi (20)

DOCX
Data Warehouse Schema (Star, Snowflake).docx
A. S. M. Shafi
 
PDF
Correlation Analysis in Machine Learning.pdf
A. S. M. Shafi
 
PDF
Naive Bayes and Decision Tree Algorithm.pdf
A. S. M. Shafi
 
PDF
Frequent Pattern Growth Mining Algorithm.pdf
A. S. M. Shafi
 
PDF
Direct Hashing and Pruning Algorithm in Data MIning.pdf
A. S. M. Shafi
 
PDF
Association Rule Mining with Apriori Algorithm.pdf
A. S. M. Shafi
 
PDF
HITS Algorithm in Data and Web MIning.pdf
A. S. M. Shafi
 
PDF
Page Rank Algorithm in Data Mining and Web Application.pdf
A. S. M. Shafi
 
PDF
K Nearest Neighbor Classifier in Machine Learning.pdf
A. S. M. Shafi
 
PDF
K Means Clustering Algorithm in Machine Learning.pdf
A. S. M. Shafi
 
PDF
2D Transformation in Computer Graphics
A. S. M. Shafi
 
PDF
3D Transformation in Computer Graphics
A. S. M. Shafi
 
PDF
Projection
A. S. M. Shafi
 
PDF
2D Transformation
A. S. M. Shafi
 
PDF
Line drawing algorithm
A. S. M. Shafi
 
PDF
Fragmentation
A. S. M. Shafi
 
PDF
File organization
A. S. M. Shafi
 
PDF
Bankers algorithm
A. S. M. Shafi
 
PDF
RR and priority scheduling
A. S. M. Shafi
 
PDF
Fcfs and sjf
A. S. M. Shafi
 
Data Warehouse Schema (Star, Snowflake).docx
A. S. M. Shafi
 
Correlation Analysis in Machine Learning.pdf
A. S. M. Shafi
 
Naive Bayes and Decision Tree Algorithm.pdf
A. S. M. Shafi
 
Frequent Pattern Growth Mining Algorithm.pdf
A. S. M. Shafi
 
Direct Hashing and Pruning Algorithm in Data MIning.pdf
A. S. M. Shafi
 
Association Rule Mining with Apriori Algorithm.pdf
A. S. M. Shafi
 
HITS Algorithm in Data and Web MIning.pdf
A. S. M. Shafi
 
Page Rank Algorithm in Data Mining and Web Application.pdf
A. S. M. Shafi
 
K Nearest Neighbor Classifier in Machine Learning.pdf
A. S. M. Shafi
 
K Means Clustering Algorithm in Machine Learning.pdf
A. S. M. Shafi
 
2D Transformation in Computer Graphics
A. S. M. Shafi
 
3D Transformation in Computer Graphics
A. S. M. Shafi
 
Projection
A. S. M. Shafi
 
2D Transformation
A. S. M. Shafi
 
Line drawing algorithm
A. S. M. Shafi
 
Fragmentation
A. S. M. Shafi
 
File organization
A. S. M. Shafi
 
Bankers algorithm
A. S. M. Shafi
 
RR and priority scheduling
A. S. M. Shafi
 
Fcfs and sjf
A. S. M. Shafi
 
Ad

Recently uploaded (20)

PDF
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
PPTX
How to Close Subscription in Odoo 18 - Odoo Slides
Celine George
 
PDF
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
PPTX
Basics and rules of probability with real-life uses
ravatkaran694
 
PPTX
Applied-Statistics-1.pptx hardiba zalaaa
hardizala899
 
PPTX
Applications of matrices In Real Life_20250724_091307_0000.pptx
gehlotkrish03
 
DOCX
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
PPTX
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
PDF
My Thoughts On Q&A- A Novel By Vikas Swarup
Niharika
 
PPTX
PROTIEN ENERGY MALNUTRITION: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
PPTX
HEALTH CARE DELIVERY SYSTEM - UNIT 2 - GNM 3RD YEAR.pptx
Priyanshu Anand
 
PPTX
Translation_ Definition, Scope & Historical Development.pptx
DhatriParmar
 
PPTX
Continental Accounting in Odoo 18 - Odoo Slides
Celine George
 
PPTX
TOP 10 AI TOOLS YOU MUST LEARN TO SURVIVE IN 2025 AND ABOVE
digilearnings.com
 
PPTX
LDP-2 UNIT 4 Presentation for practical.pptx
abhaypanchal2525
 
PPTX
ENGLISH 8 WEEK 3 Q1 - Analyzing the linguistic, historical, andor biographica...
OliverOllet
 
PPTX
INTESTINALPARASITES OR WORM INFESTATIONS.pptx
PRADEEP ABOTHU
 
PPTX
The Future of Artificial Intelligence Opportunities and Risks Ahead
vaghelajayendra784
 
PPTX
Command Palatte in Odoo 18.1 Spreadsheet - Odoo Slides
Celine George
 
PPTX
20250924 Navigating the Future: How to tell the difference between an emergen...
McGuinness Institute
 
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
How to Close Subscription in Odoo 18 - Odoo Slides
Celine George
 
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
Basics and rules of probability with real-life uses
ravatkaran694
 
Applied-Statistics-1.pptx hardiba zalaaa
hardizala899
 
Applications of matrices In Real Life_20250724_091307_0000.pptx
gehlotkrish03
 
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
My Thoughts On Q&A- A Novel By Vikas Swarup
Niharika
 
PROTIEN ENERGY MALNUTRITION: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
HEALTH CARE DELIVERY SYSTEM - UNIT 2 - GNM 3RD YEAR.pptx
Priyanshu Anand
 
Translation_ Definition, Scope & Historical Development.pptx
DhatriParmar
 
Continental Accounting in Odoo 18 - Odoo Slides
Celine George
 
TOP 10 AI TOOLS YOU MUST LEARN TO SURVIVE IN 2025 AND ABOVE
digilearnings.com
 
LDP-2 UNIT 4 Presentation for practical.pptx
abhaypanchal2525
 
ENGLISH 8 WEEK 3 Q1 - Analyzing the linguistic, historical, andor biographica...
OliverOllet
 
INTESTINALPARASITES OR WORM INFESTATIONS.pptx
PRADEEP ABOTHU
 
The Future of Artificial Intelligence Opportunities and Risks Ahead
vaghelajayendra784
 
Command Palatte in Odoo 18.1 Spreadsheet - Odoo Slides
Celine George
 
20250924 Navigating the Future: How to tell the difference between an emergen...
McGuinness Institute
 
Ad

MST

  • 1. Spanning Subgraph A subgraph of a graph, which contains all the vertices of the graph. Spanning Tree A spanning tree is a subgraph (spanning subgraph) of a graph, which contains all the vertices of the graph and contains no cycle. Minimum Cost Spanning Tree It is a spanning tree whose cost is minimum. There are two well-known algorithms to build minimum cost spanning tree. One is Prim’s algorithm and another is Kruskal’s algorithm. Prim's Algorithm Prim's algorithm is a minimum spanning tree algorithm that takes a graph as input and finds the subset of the edges of that graph which  form a tree that includes every vertex  has the minimum sum of weights among all the trees that can be formed from the graph The steps for implementing Prim's algorithm are as follows: 1. Initialize the minimum spanning tree with a vertex chosen at random. 2. Find all the edges that connect the tree to new vertices, find the minimum and add it to the tree 3. Keep repeating step 2 until we get a minimum spanning tree Example Construct the minimum spanning tree (MST) for the given graph using Prim’s Algorithm-
  • 2. Solution: Step-01 Step-02 Step-03 Step-04 Step-05 Step-06 Now, Cost of Minimum Spanning Tree = Sum of all edge weights = 10 + 25 + 22 + 12 + 16 + 14 = 99 units Prim's Algorithm pseudocode T = ∅; U = { 1 }; while (U ≠ V) let (u, v) be the lowest cost edge such that u ∈ U and v ∈ V - U; T = T ∪ {(u, v)} U = U ∪ {v}
  • 3. Kruskal's Algorithm Kruskal's algorithm is a minimum spanning tree algorithm that takes a graph as input and finds the subset of the edges of that graph which  form a tree that includes every vertex  has the minimum sum of weights among all the trees that can be formed from the graph The steps for implementing Kruskal's algorithm are as follows: 1. Sort all the edges from low weight to high 2. Take the edge with the lowest weight and add it to the spanning tree. If adding the edge created a cycle, then reject this edge. 3. Keep adding edges until we reach all vertices. Example Construct the minimum spanning tree (MST) for the given graph using Kruskal’s Algorithm- Solution Step-01 Step-02
  • 4. Step-03 Step-04 Step-05 Step-06 Weight of the MST = Sum of all edge weights = 10 + 25 + 22 + 12 + 16 + 14 = 99 units Kruskal Algorithm Pseudocode KRUSKAL(G): A = ∅ For each vertex v ∈ G.V: MAKE-SET(v) For each edge (u, v) ∈ G.E ordered by increasing order by weight(u, v): if FIND-SET(u) ≠ FIND-SET(v): A = A ∪ {(u, v)} UNION(u, v) return A