SlideShare a Scribd company logo
Minimum Spanning Tree
A spanning tree of a graph is just a subgraph that
contains all the vertices and is a tree.
A graph may have many spanning trees.
or or or
Some Spanning Trees from Graph A
Graph A
Spanning Trees
All 16 of its Spanning Trees
Complete Graph
Minimum Spanning Trees
The Minimum Spanning Tree for a given graph is the Spanning Tree of
minimum cost for that graph.
5
7
2
1
3
4
2
1
3
Complete Graph Minimum Spanning Tree
Algorithms for Obtaining the Minimum Spanning Tree
• Kruskal's Algorithm
• Prim's Algorithm
Kruskal's Algorithm
This algorithm creates a forest of trees. Initially the forest consists of n
single node trees (and no edges). At each step, we add one edge (the
cheapest one) so that it joins two trees together. If it were to form a cycle,
it would simply link two nodes that were already part of a single
connected tree, so that this edge would not be needed.
The steps are:
1. The forest is constructed - with each node in a separate tree.
2. The edges are placed in a priority queue.
3. Until we've added n-1 edges,
1. Extract the cheapest edge from the queue,
2. If it forms a cycle, reject it,
3. Else add it to the forest. Adding it to the forest will join two
trees together.
Every step will have joined two trees in the forest together, so that at
the end, there will only be one tree in T.
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
Complete Graph
1
4
2
5
2
5
4
3
4
4
4
10
1
6
3
3
2
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
A A
B D
B B
B
C D
J C
C
E
F
D
D H
J E G
F F
G I
G G
I J
H J J
I
2
5
2
5
4
3
4
4
10
1
6
3
3
2
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
B
B
D
J
C
C
E
F
D
D H
J
E G
F
F
G
I
G
G
I
J
H J
J
I
1
A D
4
B C
4
A B
Sort Edges
(in reality they are placed in a priority
queue - not sorted - but sorting them
makes the algorithm easier to visualize)
2
5
2
5
4
3
4
4
10
1
6
3
3
2
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
B
B
D
J
C
C
E
F
D
D H
J
E G
F
F
G
I
G
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
G
I
G
G
I
J
H J
J
I
1
A D
4
B C
4
A B
Add Edge
2
5
2
5
4
3
4
4
10
1
6
3
3
2
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
B
B
D
J
C
C
E
F
D
D H
J
E G
F
F
G
I
G
G
I
J
H J
J
I
1
A D
4
B C
4
A B
Add Edge
2
5
2
5
4
3
4
4
10
1
6
3
3
2
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
B
B
D
J
C
C
E
F
D
D H
J
E G
F
F
G
I
G
G
I
J
H J
J
I
1
A D
4
B C
4
A B
Cycle
Don’t Add Edge
2
5
2
5
4
3
4
4
10
1
6
3
3
2
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
B
B
D
J
C
C
E
F
D
D H
J
E G
F
F
G
I
G
G
I
J
H J
J
I
1
A D
4
B C
4
A B
Add Edge
4
1
2
2 1
3
3
2
4
A
B C
D
E F
G
H
I
J
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
Minimum Spanning Tree Complete Graph
Prim's Algorithm
This algorithm starts with one node. It then, one by one, adds a node that
is unconnected to the new graph, each time selecting the node whose
connecting edge has the smallest weight out of the available nodes’
connecting edges.
The steps are:
1. The new graph is constructed - with one node from the old graph.
2. While new graph has fewer than n nodes,
1. Find the node from the old graph with the smallest connecting
edge to the new graph,
2. Add it to the new graph
Every step will have joined one node, so that at the end we will have
one graph with all the nodes and it will be a minimum spanning tree of
the original graph.
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
Complete Graph
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
Old Graph New Graph
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
Old Graph New Graph
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
Old Graph New Graph
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
Old Graph New Graph
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
Old Graph New Graph
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
Old Graph New Graph
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
Old Graph New Graph
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
Old Graph New Graph
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
Old Graph New Graph
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
Old Graph New Graph
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J
4
1
2
2 1
3
3
2
4
A
B C
D
E F
G
H
I
J
Complete Graph Minimum Spanning Tree
4
1
2 3
2 1
3
5
3
4
2
5 6
4
4
10
A
B C
D
E F
G
H
I
J

More Related Content

PPT
Unit 5 graphs minimum spanning trees
PPT
Minimum Spanning Tree
PPTX
Minimum Spinning Tree Full Explaination pptx
PPTX
Greedy technique - Algorithm design techniques using data structures
PPT
Greedy Approach in Design Analysis and Algorithms
PPTX
APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...
Unit 5 graphs minimum spanning trees
Minimum Spanning Tree
Minimum Spinning Tree Full Explaination pptx
Greedy technique - Algorithm design techniques using data structures
Greedy Approach in Design Analysis and Algorithms
APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...

Similar to MST2.ppt (20)

PPTX
Minimum Spanning Tree (Data Structure and Algorithm)
PPT
Minimum spanning tree
PPTX
7. Spanning trees
PPTX
My presentation minimum spanning tree
PPTX
Greedy Strategy.pptxbfasjbjfn asnfn anjn
PPTX
Spanning Tree in data structure and .pptx
PPT
Graph Theory PPT presentation created by Selvam.
PPTX
DM Min SPan Tree Minimum spanning tree .pptx
PPTX
Ram minimum spanning tree
PDF
Algorithm chapter 9
PPTX
Bfs dfs mst
PDF
Skiena algorithm 2007 lecture13 minimum spanning trees
PPTX
Graph Algorithms
PPTX
11L_2024_DSCS_EN_Trees2_Prim_Kraskal.pptx
PPTX
GRAPH - DISCRETE STRUCTURE AND ALGORITHM
PPTX
uva-201026072839.pptxvcvczcvzvcxbxcvbcxvbvcxbcx
PDF
Unit-10 Graphs .pdf
PDF
Minimum Spanning Tree (MST), Kruskal's algorithm and Prim's Algorithm, and th...
PDF
Minimum spanning tree
Minimum Spanning Tree (Data Structure and Algorithm)
Minimum spanning tree
7. Spanning trees
My presentation minimum spanning tree
Greedy Strategy.pptxbfasjbjfn asnfn anjn
Spanning Tree in data structure and .pptx
Graph Theory PPT presentation created by Selvam.
DM Min SPan Tree Minimum spanning tree .pptx
Ram minimum spanning tree
Algorithm chapter 9
Bfs dfs mst
Skiena algorithm 2007 lecture13 minimum spanning trees
Graph Algorithms
11L_2024_DSCS_EN_Trees2_Prim_Kraskal.pptx
GRAPH - DISCRETE STRUCTURE AND ALGORITHM
uva-201026072839.pptxvcvczcvzvcxbxcvbcxvbvcxbcx
Unit-10 Graphs .pdf
Minimum Spanning Tree (MST), Kruskal's algorithm and Prim's Algorithm, and th...
Minimum spanning tree
Ad

Recently uploaded (20)

PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPTX
Internet of Things (IOT) - A guide to understanding
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
Sustainable Sites - Green Building Construction
PPTX
Construction Project Organization Group 2.pptx
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPT
Mechanical Engineering MATERIALS Selection
PPTX
Lecture Notes Electrical Wiring System Components
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PPT
Project quality management in manufacturing
PPT
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
PPTX
additive manufacturing of ss316l using mig welding
PPTX
bas. eng. economics group 4 presentation 1.pptx
PDF
Well-logging-methods_new................
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
Internet of Things (IOT) - A guide to understanding
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
Sustainable Sites - Green Building Construction
Construction Project Organization Group 2.pptx
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
R24 SURVEYING LAB MANUAL for civil enggi
Automation-in-Manufacturing-Chapter-Introduction.pdf
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Mechanical Engineering MATERIALS Selection
Lecture Notes Electrical Wiring System Components
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
Project quality management in manufacturing
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
additive manufacturing of ss316l using mig welding
bas. eng. economics group 4 presentation 1.pptx
Well-logging-methods_new................
Ad

MST2.ppt