SlideShare a Scribd company logo
MINIMUM SPANNING TREES
1
Presenting by:-
Muhammed Ahmed
MCA IIIrd sem.
PROBLEM: LAYING TELEPHONE WIRE
2
Central office
WIRING: NAIVE APPROACH
3
Central office
Expensive!
WIRING: BETTER APPROACH
4
Central office
Minimize the total length of wire connecting the customers
MINIMUM SPANNING TREE (MST)
5
• it is a tree (i.e., it is acyclic)
• it covers all the vertices V
– contains |V| - 1 edges
• the total cost associated with tree edges is the
minimum among all possible spanning trees
• not necessarily unique
A minimum spanning tree is a subgraph of an
undirected weighted graph G, such that
APPLICATIONS OF MST
 Any time you want to visit all vertices in a graph at
minimum cost (e.g., wire routing on printed circuit
boards, sewer pipe layout, bridges routing table, road
planning…)
 Internet content distribution
 it is a hot research topic
 Idea: publisher produces web pages, content distribution
network replicates web pages to many locations so consumers
can access at higher speed
 MST may not be good enough!
 content distribution on minimum cost tree may take a long time!
 Provides a heuristic for traveling salesman problems.
The optimum traveling salesman tour is at most twice
the length of the minimum spanning tree.
6
HOW CAN WE GENERATE A MST?
7
a
c
e
d
b
2
45
9
6
4
5
5
a
c
e
d
b
2
45
9
6
4
5
5
PRIM’S ALGORITHM
8
Initialization
a. Pick a vertex r to be the root
b. Set D(r) = 0, parent(r) = null
c. For all vertices v  V, v  r, set D(v) = 
d. Insert all vertices into priority queue P,
using distances as the keys
a
c
e
d
b
2
45
9
6
4
5
5
e a b c d
0    
Vertex Parent
e -
PRIM’S ALGORITHM
9
While P is not empty:
1. Select the next vertex u to add to the tree
u = P.deleteMin()
2. Update the weight of each vertex w adjacent to
u which is not in the tree (i.e., w  P)
If weight(u,w) < D(w),
a. parent(w) = u
b. D(w) = weight(u,w)
c. Update the priority queue to reflect
new distance for w
PRIM’S ALGORITHM
10
a
c
e
d
b
2
45
9
6
4
5
5
d b c a
4 5 5 
Vertex Parent
e -
b e
c e
d e
The MST initially consists of the vertex e, and we update
the distances and parent for its adjacent vertices
Vertex Parent
e -
b -
c -
d -
d b c a
   
e
0
PRIM’S ALGORITHM
11
a
c
e
d
b
2
45
9
6
4
5
5
a c b
2 4 5
Vertex Parent
e -
b e
c d
d e
a d
d b c a
4 5 5 
Vertex Parent
e -
b e
c e
d e
PRIM’S ALGORITHM
12
a
c
e
d
b
2
45
9
6
4
5
5
c b
4 5
Vertex Parent
e -
b e
c d
d e
a d
a c b
2 4 5
Vertex Parent
e -
b e
c d
d e
a d
PRIM’S ALGORITHM
13
a
c
e
d
b
2
45
9
6
4
5
5
b
5
Vertex Parent
e -
b e
c d
d e
a d
c b
4 5
Vertex Parent
e -
b e
c d
d e
a d
PRIM’S ALGORITHM
14
Vertex Parent
e -
b e
c d
d e
a d
a
c
e
d
b
2
45
9
6
4
5
5
The final minimum spanning tree
b
5
Vertex Parent
e -
b e
c d
d e
a d
KRUSKAL’S ALGORITHM
15
Initialization
a. Create a set for each vertex v  V
b. Initialize the set of “safe edges” A
comprising the MST to the empty set
c. Sort edges by increasing weight
a
c
e
d
b
2
45
9
6
4
5
5
F = {a}, {b}, {c}, {d}, {e}
A = 
E = {(a,d), (c,d), (d,e), (a,c),
(b,e), (c,e), (b,d), (a,b)}
KRUSKAL’S ALGORITHM
16
For each edge (u,v)  E in increasing order
while more than one set remains:
If u and v, belong to different sets U and V
a. add edge (u,v) to the safe edge set
A = A  {(u,v)}
b. merge the sets U and V
F = F - U - V + (U  V)
Return A
KRUSKAL’S ALGORITHM
17
E = {(a,d), (c,d), (d,e), (a,c),
(b,e), (c,e), (b,d), (a,b)}
Forest
{a}, {b}, {c}, {d}, {e}
{a,d}, {b}, {c}, {e}
{a,d,c}, {b}, {e}
{a,d,c,e}, {b}
{a,d,c,e,b}
A

{(a,d)}
{(a,d), (c,d)}
{(a,d), (c,d), (d,e)}
{(a,d), (c,d), (d,e), (b,e)}
a
c
e
d
b
2
45
9
6
4
5
5
COMPLEXITY
 Kruskal's algorithm can be shown to run
in O(E log E) time, or equivalently, O(E log V)
time. Where E is the number of edges in the
graph and V is the number of vertices.
 The time complexity of prim’s Algorithm is
given by:
T(n)=2(n-1)(n-1) є Ө(n2)
where n=no. of vertices.
18
DIFFERENCE
 The basic difference is in which edge you choose to add next to
the spanning tree in each step.
In Prim's, we always keep a connected component, starting with a
single vertex. we look at all edges from the current component to
other vertices and find the smallest among them. we then add the
neighboring vertex to the component, increasing its size by 1. In
N-1 steps, every vertex would be merged to the current one if we
have a connected graph.
In Kruskal's, we do not keep one connected component but a
forest. At each stage, we look at the globally smallest edge that
does not create a cycle in the current forest. Such an edge has to
necessarily merge two trees in the current forest into one. Since
we start with N single-vertex trees, in N-1 steps, they would all
have merged into one if the graph was connected.
19
GREEDY APPROACH
 Both Prim’s and Kruskal’s algorithms are greedy
algorithms.
 The greedy approach works for the MST problem;
however, it does not work for many other
problems!
20
That’s All

More Related Content

PPT
minimum spanning trees Algorithm
PPTX
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
PDF
19 Minimum Spanning Trees
PPTX
Spanning trees & applications
PDF
Minimum spanning tree
PPTX
Minimum spanning tree
PPTX
Minimum spanning Tree
PPTX
Kruskal Algorithm
minimum spanning trees Algorithm
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
19 Minimum Spanning Trees
Spanning trees & applications
Minimum spanning tree
Minimum spanning tree
Minimum spanning Tree
Kruskal Algorithm

What's hot (20)

PPTX
Kruskal's algorithm
PPT
Spanning trees
PPT
ADA - Minimum Spanning Tree Prim Kruskal and Dijkstra
PPT
KRUSKAL'S algorithm from chaitra
PDF
Algorithms explained
PPTX
Prims & kruskal algorithms
PDF
20 Single Source Shorthest Path
PDF
Topological sorting
PPT
Prim Algorithm and kruskal algorithm
PDF
Prim algorithm
PPTX
Minimum spanning tree algorithms by ibrahim_alfayoumi
PPT
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
PPTX
Data Algorithms And Analysis
PDF
Graph Theory: Connectivity & Isomorphism
PPT
Prim's Algorithm on minimum spanning tree
PPTX
My presentation minimum spanning tree
PDF
Dynamic Programming Over Graphs of Bounded Treewidth
PDF
Paths and Polynomials
PPT
chapter24.ppt
PPTX
Connectivity of graph
Kruskal's algorithm
Spanning trees
ADA - Minimum Spanning Tree Prim Kruskal and Dijkstra
KRUSKAL'S algorithm from chaitra
Algorithms explained
Prims & kruskal algorithms
20 Single Source Shorthest Path
Topological sorting
Prim Algorithm and kruskal algorithm
Prim algorithm
Minimum spanning tree algorithms by ibrahim_alfayoumi
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Data Algorithms And Analysis
Graph Theory: Connectivity & Isomorphism
Prim's Algorithm on minimum spanning tree
My presentation minimum spanning tree
Dynamic Programming Over Graphs of Bounded Treewidth
Paths and Polynomials
chapter24.ppt
Connectivity of graph
Ad

Similar to Minimum spanning tree (20)

PPTX
_A C program for Prim's Minimum Spanning Tree (MST) algorithm. The program is...
PDF
Ijciras1101
PPT
Greedy Approach in Design Analysis and Algorithms
PDF
DATA STRUCTURES & ALGORITHMS MINIMUM SPANNING TREE
PPT
Minimum spanning tree
PPTX
Greedy Strategy.pptxbfasjbjfn asnfn anjn
PPTX
APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...
PPTX
Minimum Spanning Tree (Data Structure and Algorithm)
PPTX
Minimum Spinning Tree Full Explaination pptx
PDF
15 chapter9 graph_algorithms_mst
PPT
Minimum Spanning Tree
PPTX
Minimum spanning tree.pptx data structure programming
PPTX
Ram minimum spanning tree
PPT
minimum spanning tree
PPTX
A tree is an acyclic, undirected, connected graph • A spanning tree of a grap...
PDF
Minimum-Spanning-Tree.pdf ramswaroop memorial University
PPTX
Greedy technique - Algorithm design techniques using data structures
PPTX
11L_2024_DSCS_EN_Trees2_Prim_Kraskal.pptx
PPT
Graph Theory PPT presentation created by Selvam.
_A C program for Prim's Minimum Spanning Tree (MST) algorithm. The program is...
Ijciras1101
Greedy Approach in Design Analysis and Algorithms
DATA STRUCTURES & ALGORITHMS MINIMUM SPANNING TREE
Minimum spanning tree
Greedy Strategy.pptxbfasjbjfn asnfn anjn
APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...
Minimum Spanning Tree (Data Structure and Algorithm)
Minimum Spinning Tree Full Explaination pptx
15 chapter9 graph_algorithms_mst
Minimum Spanning Tree
Minimum spanning tree.pptx data structure programming
Ram minimum spanning tree
minimum spanning tree
A tree is an acyclic, undirected, connected graph • A spanning tree of a grap...
Minimum-Spanning-Tree.pdf ramswaroop memorial University
Greedy technique - Algorithm design techniques using data structures
11L_2024_DSCS_EN_Trees2_Prim_Kraskal.pptx
Graph Theory PPT presentation created by Selvam.
Ad

Recently uploaded (20)

PDF
Design Guidelines and solutions for Plastics parts
PPTX
introduction to high performance computing
PDF
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
PPTX
Graph Data Structures with Types, Traversals, Connectivity, and Real-Life App...
PDF
UNIT no 1 INTRODUCTION TO DBMS NOTES.pdf
PPT
Occupational Health and Safety Management System
PDF
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
PDF
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
PDF
August 2025 - Top 10 Read Articles in Network Security & Its Applications
PPTX
Nature of X-rays, X- Ray Equipment, Fluoroscopy
PDF
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
PPT
Total quality management ppt for engineering students
PDF
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
PPTX
Safety Seminar civil to be ensured for safe working.
PDF
Accra-Kumasi Expressway - Prefeasibility Report Volume 1 of 7.11.2018.pdf
PPTX
Artificial Intelligence
PDF
Soil Improvement Techniques Note - Rabbi
PDF
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
PPTX
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
Design Guidelines and solutions for Plastics parts
introduction to high performance computing
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
Graph Data Structures with Types, Traversals, Connectivity, and Real-Life App...
UNIT no 1 INTRODUCTION TO DBMS NOTES.pdf
Occupational Health and Safety Management System
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
August 2025 - Top 10 Read Articles in Network Security & Its Applications
Nature of X-rays, X- Ray Equipment, Fluoroscopy
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
Total quality management ppt for engineering students
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
Safety Seminar civil to be ensured for safe working.
Accra-Kumasi Expressway - Prefeasibility Report Volume 1 of 7.11.2018.pdf
Artificial Intelligence
Soil Improvement Techniques Note - Rabbi
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
Automation-in-Manufacturing-Chapter-Introduction.pdf

Minimum spanning tree

  • 1. MINIMUM SPANNING TREES 1 Presenting by:- Muhammed Ahmed MCA IIIrd sem.
  • 2. PROBLEM: LAYING TELEPHONE WIRE 2 Central office
  • 4. WIRING: BETTER APPROACH 4 Central office Minimize the total length of wire connecting the customers
  • 5. MINIMUM SPANNING TREE (MST) 5 • it is a tree (i.e., it is acyclic) • it covers all the vertices V – contains |V| - 1 edges • the total cost associated with tree edges is the minimum among all possible spanning trees • not necessarily unique A minimum spanning tree is a subgraph of an undirected weighted graph G, such that
  • 6. APPLICATIONS OF MST  Any time you want to visit all vertices in a graph at minimum cost (e.g., wire routing on printed circuit boards, sewer pipe layout, bridges routing table, road planning…)  Internet content distribution  it is a hot research topic  Idea: publisher produces web pages, content distribution network replicates web pages to many locations so consumers can access at higher speed  MST may not be good enough!  content distribution on minimum cost tree may take a long time!  Provides a heuristic for traveling salesman problems. The optimum traveling salesman tour is at most twice the length of the minimum spanning tree. 6
  • 7. HOW CAN WE GENERATE A MST? 7 a c e d b 2 45 9 6 4 5 5 a c e d b 2 45 9 6 4 5 5
  • 8. PRIM’S ALGORITHM 8 Initialization a. Pick a vertex r to be the root b. Set D(r) = 0, parent(r) = null c. For all vertices v  V, v  r, set D(v) =  d. Insert all vertices into priority queue P, using distances as the keys a c e d b 2 45 9 6 4 5 5 e a b c d 0     Vertex Parent e -
  • 9. PRIM’S ALGORITHM 9 While P is not empty: 1. Select the next vertex u to add to the tree u = P.deleteMin() 2. Update the weight of each vertex w adjacent to u which is not in the tree (i.e., w  P) If weight(u,w) < D(w), a. parent(w) = u b. D(w) = weight(u,w) c. Update the priority queue to reflect new distance for w
  • 10. PRIM’S ALGORITHM 10 a c e d b 2 45 9 6 4 5 5 d b c a 4 5 5  Vertex Parent e - b e c e d e The MST initially consists of the vertex e, and we update the distances and parent for its adjacent vertices Vertex Parent e - b - c - d - d b c a     e 0
  • 11. PRIM’S ALGORITHM 11 a c e d b 2 45 9 6 4 5 5 a c b 2 4 5 Vertex Parent e - b e c d d e a d d b c a 4 5 5  Vertex Parent e - b e c e d e
  • 12. PRIM’S ALGORITHM 12 a c e d b 2 45 9 6 4 5 5 c b 4 5 Vertex Parent e - b e c d d e a d a c b 2 4 5 Vertex Parent e - b e c d d e a d
  • 13. PRIM’S ALGORITHM 13 a c e d b 2 45 9 6 4 5 5 b 5 Vertex Parent e - b e c d d e a d c b 4 5 Vertex Parent e - b e c d d e a d
  • 14. PRIM’S ALGORITHM 14 Vertex Parent e - b e c d d e a d a c e d b 2 45 9 6 4 5 5 The final minimum spanning tree b 5 Vertex Parent e - b e c d d e a d
  • 15. KRUSKAL’S ALGORITHM 15 Initialization a. Create a set for each vertex v  V b. Initialize the set of “safe edges” A comprising the MST to the empty set c. Sort edges by increasing weight a c e d b 2 45 9 6 4 5 5 F = {a}, {b}, {c}, {d}, {e} A =  E = {(a,d), (c,d), (d,e), (a,c), (b,e), (c,e), (b,d), (a,b)}
  • 16. KRUSKAL’S ALGORITHM 16 For each edge (u,v)  E in increasing order while more than one set remains: If u and v, belong to different sets U and V a. add edge (u,v) to the safe edge set A = A  {(u,v)} b. merge the sets U and V F = F - U - V + (U  V) Return A
  • 17. KRUSKAL’S ALGORITHM 17 E = {(a,d), (c,d), (d,e), (a,c), (b,e), (c,e), (b,d), (a,b)} Forest {a}, {b}, {c}, {d}, {e} {a,d}, {b}, {c}, {e} {a,d,c}, {b}, {e} {a,d,c,e}, {b} {a,d,c,e,b} A  {(a,d)} {(a,d), (c,d)} {(a,d), (c,d), (d,e)} {(a,d), (c,d), (d,e), (b,e)} a c e d b 2 45 9 6 4 5 5
  • 18. COMPLEXITY  Kruskal's algorithm can be shown to run in O(E log E) time, or equivalently, O(E log V) time. Where E is the number of edges in the graph and V is the number of vertices.  The time complexity of prim’s Algorithm is given by: T(n)=2(n-1)(n-1) є Ө(n2) where n=no. of vertices. 18
  • 19. DIFFERENCE  The basic difference is in which edge you choose to add next to the spanning tree in each step. In Prim's, we always keep a connected component, starting with a single vertex. we look at all edges from the current component to other vertices and find the smallest among them. we then add the neighboring vertex to the component, increasing its size by 1. In N-1 steps, every vertex would be merged to the current one if we have a connected graph. In Kruskal's, we do not keep one connected component but a forest. At each stage, we look at the globally smallest edge that does not create a cycle in the current forest. Such an edge has to necessarily merge two trees in the current forest into one. Since we start with N single-vertex trees, in N-1 steps, they would all have merged into one if the graph was connected. 19
  • 20. GREEDY APPROACH  Both Prim’s and Kruskal’s algorithms are greedy algorithms.  The greedy approach works for the MST problem; however, it does not work for many other problems! 20