SlideShare a Scribd company logo
Minimum Spanning Trees
CSE 373
Data Structures
6/13/2023 CSE 373 AU 04 - Minimum
Spanning Trees
2
Spanning Trees
• Given (connected) graph G(V,E),
a spanning tree T(V’,E’):
› Is a subgraph of G; that is, V’  V, E’  E.
› Spans the graph (V’ = V)
› Forms a tree (no cycle);
› So, E’ has |V| -1 edges
6/13/2023 CSE 373 AU 04 - Minimum
Spanning Trees
3
Minimum Spanning Trees
• Edges are weighted: find minimum cost
spanning tree
• Applications
› Find cheapest way to wire your house
› Find minimum cost to send a message on
the Internet
6/13/2023 CSE 373 AU 04 - Minimum
Spanning Trees
4
Strategy for Minimum
Spanning Tree
• For any spanning tree T, inserting an
edge enew not in T creates a cycle
• But
› Removing any edge eold from the cycle
gives back a spanning tree
› If enew has a lower cost than eold we have
progressed!
6/13/2023 CSE 373 AU 04 - Minimum
Spanning Trees
5
Strategy
• Strategy for construction:
› Add an edge of minimum cost that does
not create a cycle (greedy algorithm)
› Repeat |V| -1 times
› Correct since if we could replace an edge
with one of lower cost, the algorithm would
have picked it up
6/13/2023 CSE 373 AU 04 - Minimum
Spanning Trees
6
Two Algorithms
• Prim: (build tree incrementally)
› Pick lower cost edge connected to known
(incomplete) spanning tree that does not create a
cycle and expand to include it in the tree
• Kruskal: (build forest that will finish as a tree)
› Pick lowest cost edge not yet in a tree that does
not create a cycle. Then expand the set of
included edges to include it. (It will be somewhere
in the forest.)
6/13/2023 CSE 373 AU 04 - Minimum
Spanning Trees
7
Prim’s algorithm
1
2 3 4
6 5
10
1
5
8 3
1 1 6
2
4
Starting from empty T,
choose a vertex at
random and initialize
V = {1), E’ ={}
6/13/2023 CSE 373 AU 04 - Minimum
Spanning Trees
8
Prim’s algorithm
1
2 3 4
6 5
10
1
5
8 3
1 1 6
2
4
Choose the vertex u not in
V such that edge weight
from u to a vertex in V is
minimal (greedy!)
V={1,3} E’= {(1,3) }
6/13/2023 CSE 373 AU 04 - Minimum
Spanning Trees
9
Prim’s algorithm
1
2 3 4
6 5
10
1
5
8 3
1 1 6
2
4
Repeat until all vertices have
been chosen
Choose the vertex u not in V
such that edge weight from v to a
vertex in V is minimal (greedy!)
V= {1,3,4} E’= {(1,3),(3,4)}
V={1,3,4,5} E’={(1,3),(3,4),(4,5)}
….
V={1,3,4,5,2,6}
E’={(1,3),(3,4),(4,5),(5,2),(2,6)}
6/13/2023 CSE 373 AU 04 - Minimum
Spanning Trees
10
Prim’s algorithm
1
2 3 4
6 5
10
1
5
8 3
1 1 6
2
4
Repeat until all vertices have
been chosen
V={1,3,4,5,2,6}
E’={(1,3),(3,4),(4,5),(5,2),(2,6)}
Final Cost: 1 + 3 + 4 + 1 + 1 = 10
6/13/2023 CSE 373 AU 04 - Minimum
Spanning Trees
11
Prim’s Algorithm
Implementation
• Assume adjacency list representation
Initialize connection cost of each node to “inf” and “unmark” them
Choose one node, say v and set cost[v] = 0 and prev[v] =0
While they are unmarked nodes
Select the unmarked node u with minimum cost; mark it
For each unmarked node w adjacent to u
if cost(u,w) < cost(w) then cost(w) := cost (u,w)
prev[w] = u
6/13/2023 CSE 373 AU 04 - Minimum
Spanning Trees
12
Prim’s algorithm Analysis
• If the “Select the unmarked node u with minimum cost” is
done with binary heap then O((n+m)logn)
6/13/2023 CSE 373 AU 04 - Minimum
Spanning Trees
13
Kruskal’s Algorithm
• Select edges in order of increasing cost
• Accept an edge to expand tree or forest
only if it does not cause a cycle
• Implementation using adjacency list,
priority queues and disjoint sets
6/13/2023 CSE 373 AU 04 - Minimum
Spanning Trees
14
Kruskal’s Algorithm
Initialize a forest of trees, each tree being a single node
Build a priority queue of edges with priority being lowest cost
Repeat until |V| -1 edges have been accepted {
Deletemin edge from priority queue
If it forms a cycle then discard it
else accept the edge – It will join 2 existing trees yielding a
larger tree and reducing the forest by one tree
}
The accepted edges form the minimum spanning tree
6/13/2023 CSE 373 AU 04 - Minimum
Spanning Trees
15
Detecting Cycles
• If the edge to be added (u,v) is such
that vertices u and v belong to the same
tree, then by adding (u,v) you would
form a cycle
› Therefore to check, Find(u) and Find(v). If
they are the same discard (u,v)
› If they are different Union(Find(u),Find(v))
6/13/2023 CSE 373 AU 04 - Minimum
Spanning Trees
16
Properties of trees in K’s
algorithm
• Vertices in different trees are disjoint
› True at initialization and Union won’t modify the
fact for remaining trees
• Trees form equivalent classes under the
relation “is connected to”
› u connected to u (reflexivity)
› u connected to v implies v connected to u
(symmetry)
› u connected to v and v connected to w implies a
path from u to w so u connected to w (transitivity)
6/13/2023 CSE 373 AU 04 - Minimum
Spanning Trees
17
K’s Algorithm Data Structures
• Adjacency list for the graph
› To perform the initialization of the data
structures below
• Disjoint Set ADT’s for the trees (recall
Up tree implementation of Union-Find)
• Binary heap for edges
6/13/2023 CSE 373 AU 04 - Minimum
Spanning Trees
18
Example
1
2 3 4
6 5
10
1
5
8 3
1 1 6
2
4
1
6/13/2023 CSE 373 AU 04 - Minimum
Spanning Trees
19
1
2 3 4
6 5
10
1
5
8 3
1 1 6
2
4
1
6/13/2023 CSE 373 AU 04 - Minimum
Spanning Trees
20
Initialization
1
2 3 4
6 5
Initially, Forest of 6 trees
F= {{1},{2},{3},{4},{5},{6}}
Edges in a heap (not
shown)
6/13/2023 CSE 373 AU 04 - Minimum
Spanning Trees
21
Step 1
1
2 3 4
6 5
Select edge with lowest
cost (2,5)
Find(2) = 2, Find (5) = 5
Union(2,5)
F= {{1},{2,5},{3},{4},{6}}
1 edge accepted 1
6/13/2023 CSE 373 AU 04 - Minimum
Spanning Trees
22
Step 2
1
2 3 4
6 5
Select edge with lowest
cost (2,6)
Find(2) = 2, Find (6) = 6
Union(2,6)
F= {{1},{2,5,6},{3},{4}}
2 edges accepted 1
1
6/13/2023 CSE 373 AU 04 - Minimum
Spanning Trees
23
Step 3
1
2 3 4
6 5
Select edge with lowest
cost (1,3)
Find(1) = 1, Find (3) = 3
Union(1,3)
F= {{1,3},{2,5,6},{4}}
3 edges accepted 1
1
1
6/13/2023 CSE 373 AU 04 - Minimum
Spanning Trees
24
Step 4
1
2 3 4
6 5
Select edge with lowest
cost (5,6)
Find(5) = 2, Find (6) = 2
Do nothing
F= {{1,3},{2,5,6},{4}}
3 edges accepted 1
1
1
6/13/2023 CSE 373 AU 04 - Minimum
Spanning Trees
25
Step 5
1
2 3 4
6 5
Select edge with lowest
cost (3,4)
Find(3) = 1, Find (4) = 4
Union(1,4)
F= {{1,3,4},{2,5,6}}
4 edges accepted 1
1
1
3
6/13/2023 CSE 373 AU 04 - Minimum
Spanning Trees
26
Step 6
1
2 3 4
6 5
Select edge with lowest
cost (4,5)
Find(4) = 1, Find (5) = 2
Union(1,2)
F= {{1,3,4,2,5,6}}
5 edges accepted : end
Total cost = 10
Although there is a unique
spanning tree in this
example, this is not
generally the case
1
1
1
3
4
6/13/2023 CSE 373 AU 04 - Minimum
Spanning Trees
27
Kruskal’s Algorithm Analysis
• Initialize forest O(n)
• Initialize heap O(m), m = |E|
• Loop performed m times
› In the loop one DeleteMin O(log m)
› Two Find, each O(log n)
› One Union (at most) O(1)
• So worst case O(m log m) = O(m log n)
6/13/2023 CSE 373 AU 04 - Minimum
Spanning Trees
28
Time Complexity Summary
• Recall that m = |E| = O(V2) = O(n2 )
• Prim’s runs in O((n+m) log n)
• Kruskal runs in O(m log m) = O(m log n)
• In practice, Kruskal has a tendency to
run faster since graphs might not be
dense and not all edges need to be
looked at in the Deletemin operations

More Related Content

Similar to MinSpanningTreespresantion.ppt

Day 5 application of graph ,biconnectivity fdp on ds
Day 5 application of graph ,biconnectivity fdp on dsDay 5 application of graph ,biconnectivity fdp on ds
Day 5 application of graph ,biconnectivity fdp on ds
GUNASUNDARISAPIIICSE
 
prim's and kruskal's algorithm
prim's and kruskal's algorithmprim's and kruskal's algorithm
prim's and kruskal's algorithm
shreeuva
 
Kruskal Algorithm
Kruskal AlgorithmKruskal Algorithm
Kruskal Algorithm
Bhavik Vashi
 
Graph Theory: Trees
Graph Theory: TreesGraph Theory: Trees
Graph Theory: Trees
Ashikur Rahman
 
Graph 2
Graph 2Graph 2
Design and Analysis of Algorithm -Shortest paths problem
Design and Analysis of Algorithm -Shortest paths problemDesign and Analysis of Algorithm -Shortest paths problem
Design and Analysis of Algorithm -Shortest paths problem
pooja saini
 
8_MST_pptx.pptx
8_MST_pptx.pptx8_MST_pptx.pptx
8_MST_pptx.pptx
JhonCarloJacinto
 
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
Madhu Bala
 
Algorithm chapter 9
Algorithm chapter 9Algorithm chapter 9
Algorithm chapter 9
chidabdu
 
Minimum spanning tree
Minimum spanning treeMinimum spanning tree
Minimum spanning tree
Hinal Lunagariya
 
Minimum Spanning Tree
Minimum Spanning TreeMinimum Spanning Tree
Minimum Spanning Tree
Balamurugan M
 
Farhana shaikh webinar_spanning tree
Farhana shaikh webinar_spanning treeFarhana shaikh webinar_spanning tree
Farhana shaikh webinar_spanning tree
Farhana Shaikh
 
Minimum Spanning Tree using Kruskal's Algorithm
Minimum Spanning Tree using Kruskal's Algorithm Minimum Spanning Tree using Kruskal's Algorithm
Minimum Spanning Tree using Kruskal's Algorithm
Mrunal Patil
 
post119s1-file2
post119s1-file2post119s1-file2
post119s1-file2
Venkata Suhas Maringanti
 
Shortest Path Problem.docx
Shortest Path Problem.docxShortest Path Problem.docx
Shortest Path Problem.docx
SeethaDinesh
 
19 Minimum Spanning Trees
19 Minimum Spanning Trees19 Minimum Spanning Trees
19 Minimum Spanning Trees
Andres Mendez-Vazquez
 
Ijciras1101
Ijciras1101Ijciras1101
Ijciras1101
zhendy94
 
Kruskal's algorithm
Kruskal's algorithmKruskal's algorithm
Kruskal's algorithm
Raj Kumar Ranabhat
 
Steiner Minimal Trees
Steiner Minimal TreesSteiner Minimal Trees
Steiner Minimal Trees
tbadri
 
Skiena algorithm 2007 lecture13 minimum spanning trees
Skiena algorithm 2007 lecture13 minimum spanning treesSkiena algorithm 2007 lecture13 minimum spanning trees
Skiena algorithm 2007 lecture13 minimum spanning trees
zukun
 

Similar to MinSpanningTreespresantion.ppt (20)

Day 5 application of graph ,biconnectivity fdp on ds
Day 5 application of graph ,biconnectivity fdp on dsDay 5 application of graph ,biconnectivity fdp on ds
Day 5 application of graph ,biconnectivity fdp on ds
 
prim's and kruskal's algorithm
prim's and kruskal's algorithmprim's and kruskal's algorithm
prim's and kruskal's algorithm
 
Kruskal Algorithm
Kruskal AlgorithmKruskal Algorithm
Kruskal Algorithm
 
Graph Theory: Trees
Graph Theory: TreesGraph Theory: Trees
Graph Theory: Trees
 
Graph 2
Graph 2Graph 2
Graph 2
 
Design and Analysis of Algorithm -Shortest paths problem
Design and Analysis of Algorithm -Shortest paths problemDesign and Analysis of Algorithm -Shortest paths problem
Design and Analysis of Algorithm -Shortest paths problem
 
8_MST_pptx.pptx
8_MST_pptx.pptx8_MST_pptx.pptx
8_MST_pptx.pptx
 
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
 
Algorithm chapter 9
Algorithm chapter 9Algorithm chapter 9
Algorithm chapter 9
 
Minimum spanning tree
Minimum spanning treeMinimum spanning tree
Minimum spanning tree
 
Minimum Spanning Tree
Minimum Spanning TreeMinimum Spanning Tree
Minimum Spanning Tree
 
Farhana shaikh webinar_spanning tree
Farhana shaikh webinar_spanning treeFarhana shaikh webinar_spanning tree
Farhana shaikh webinar_spanning tree
 
Minimum Spanning Tree using Kruskal's Algorithm
Minimum Spanning Tree using Kruskal's Algorithm Minimum Spanning Tree using Kruskal's Algorithm
Minimum Spanning Tree using Kruskal's Algorithm
 
post119s1-file2
post119s1-file2post119s1-file2
post119s1-file2
 
Shortest Path Problem.docx
Shortest Path Problem.docxShortest Path Problem.docx
Shortest Path Problem.docx
 
19 Minimum Spanning Trees
19 Minimum Spanning Trees19 Minimum Spanning Trees
19 Minimum Spanning Trees
 
Ijciras1101
Ijciras1101Ijciras1101
Ijciras1101
 
Kruskal's algorithm
Kruskal's algorithmKruskal's algorithm
Kruskal's algorithm
 
Steiner Minimal Trees
Steiner Minimal TreesSteiner Minimal Trees
Steiner Minimal Trees
 
Skiena algorithm 2007 lecture13 minimum spanning trees
Skiena algorithm 2007 lecture13 minimum spanning treesSkiena algorithm 2007 lecture13 minimum spanning trees
Skiena algorithm 2007 lecture13 minimum spanning trees
 

Recently uploaded

官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
171ticu
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Sinan KOZAK
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
Madan Karki
 
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
University of Maribor
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
insn4465
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
gerogepatton
 
Textile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdfTextile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdf
NazakatAliKhoso2
 
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptxML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
JamalHussainArman
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
kandramariana6
 
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
ihlasbinance2003
 
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEMTIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
HODECEDSIET
 
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball playEric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
enizeyimana36
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
camseq
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
NidhalKahouli2
 
Question paper of renewable energy sources
Question paper of renewable energy sourcesQuestion paper of renewable energy sources
Question paper of renewable energy sources
mahammadsalmanmech
 
New techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdfNew techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdf
wisnuprabawa3
 
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have oneISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
Las Vegas Warehouse
 
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
171ticu
 
Heat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation pptHeat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation ppt
mamunhossenbd75
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
Madan Karki
 

Recently uploaded (20)

官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
 
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
 
Textile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdfTextile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdf
 
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptxML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
 
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
 
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEMTIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
 
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball playEric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
 
Question paper of renewable energy sources
Question paper of renewable energy sourcesQuestion paper of renewable energy sources
Question paper of renewable energy sources
 
New techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdfNew techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdf
 
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have oneISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
 
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
 
Heat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation pptHeat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation ppt
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
 

MinSpanningTreespresantion.ppt

  • 1. Minimum Spanning Trees CSE 373 Data Structures
  • 2. 6/13/2023 CSE 373 AU 04 - Minimum Spanning Trees 2 Spanning Trees • Given (connected) graph G(V,E), a spanning tree T(V’,E’): › Is a subgraph of G; that is, V’  V, E’  E. › Spans the graph (V’ = V) › Forms a tree (no cycle); › So, E’ has |V| -1 edges
  • 3. 6/13/2023 CSE 373 AU 04 - Minimum Spanning Trees 3 Minimum Spanning Trees • Edges are weighted: find minimum cost spanning tree • Applications › Find cheapest way to wire your house › Find minimum cost to send a message on the Internet
  • 4. 6/13/2023 CSE 373 AU 04 - Minimum Spanning Trees 4 Strategy for Minimum Spanning Tree • For any spanning tree T, inserting an edge enew not in T creates a cycle • But › Removing any edge eold from the cycle gives back a spanning tree › If enew has a lower cost than eold we have progressed!
  • 5. 6/13/2023 CSE 373 AU 04 - Minimum Spanning Trees 5 Strategy • Strategy for construction: › Add an edge of minimum cost that does not create a cycle (greedy algorithm) › Repeat |V| -1 times › Correct since if we could replace an edge with one of lower cost, the algorithm would have picked it up
  • 6. 6/13/2023 CSE 373 AU 04 - Minimum Spanning Trees 6 Two Algorithms • Prim: (build tree incrementally) › Pick lower cost edge connected to known (incomplete) spanning tree that does not create a cycle and expand to include it in the tree • Kruskal: (build forest that will finish as a tree) › Pick lowest cost edge not yet in a tree that does not create a cycle. Then expand the set of included edges to include it. (It will be somewhere in the forest.)
  • 7. 6/13/2023 CSE 373 AU 04 - Minimum Spanning Trees 7 Prim’s algorithm 1 2 3 4 6 5 10 1 5 8 3 1 1 6 2 4 Starting from empty T, choose a vertex at random and initialize V = {1), E’ ={}
  • 8. 6/13/2023 CSE 373 AU 04 - Minimum Spanning Trees 8 Prim’s algorithm 1 2 3 4 6 5 10 1 5 8 3 1 1 6 2 4 Choose the vertex u not in V such that edge weight from u to a vertex in V is minimal (greedy!) V={1,3} E’= {(1,3) }
  • 9. 6/13/2023 CSE 373 AU 04 - Minimum Spanning Trees 9 Prim’s algorithm 1 2 3 4 6 5 10 1 5 8 3 1 1 6 2 4 Repeat until all vertices have been chosen Choose the vertex u not in V such that edge weight from v to a vertex in V is minimal (greedy!) V= {1,3,4} E’= {(1,3),(3,4)} V={1,3,4,5} E’={(1,3),(3,4),(4,5)} …. V={1,3,4,5,2,6} E’={(1,3),(3,4),(4,5),(5,2),(2,6)}
  • 10. 6/13/2023 CSE 373 AU 04 - Minimum Spanning Trees 10 Prim’s algorithm 1 2 3 4 6 5 10 1 5 8 3 1 1 6 2 4 Repeat until all vertices have been chosen V={1,3,4,5,2,6} E’={(1,3),(3,4),(4,5),(5,2),(2,6)} Final Cost: 1 + 3 + 4 + 1 + 1 = 10
  • 11. 6/13/2023 CSE 373 AU 04 - Minimum Spanning Trees 11 Prim’s Algorithm Implementation • Assume adjacency list representation Initialize connection cost of each node to “inf” and “unmark” them Choose one node, say v and set cost[v] = 0 and prev[v] =0 While they are unmarked nodes Select the unmarked node u with minimum cost; mark it For each unmarked node w adjacent to u if cost(u,w) < cost(w) then cost(w) := cost (u,w) prev[w] = u
  • 12. 6/13/2023 CSE 373 AU 04 - Minimum Spanning Trees 12 Prim’s algorithm Analysis • If the “Select the unmarked node u with minimum cost” is done with binary heap then O((n+m)logn)
  • 13. 6/13/2023 CSE 373 AU 04 - Minimum Spanning Trees 13 Kruskal’s Algorithm • Select edges in order of increasing cost • Accept an edge to expand tree or forest only if it does not cause a cycle • Implementation using adjacency list, priority queues and disjoint sets
  • 14. 6/13/2023 CSE 373 AU 04 - Minimum Spanning Trees 14 Kruskal’s Algorithm Initialize a forest of trees, each tree being a single node Build a priority queue of edges with priority being lowest cost Repeat until |V| -1 edges have been accepted { Deletemin edge from priority queue If it forms a cycle then discard it else accept the edge – It will join 2 existing trees yielding a larger tree and reducing the forest by one tree } The accepted edges form the minimum spanning tree
  • 15. 6/13/2023 CSE 373 AU 04 - Minimum Spanning Trees 15 Detecting Cycles • If the edge to be added (u,v) is such that vertices u and v belong to the same tree, then by adding (u,v) you would form a cycle › Therefore to check, Find(u) and Find(v). If they are the same discard (u,v) › If they are different Union(Find(u),Find(v))
  • 16. 6/13/2023 CSE 373 AU 04 - Minimum Spanning Trees 16 Properties of trees in K’s algorithm • Vertices in different trees are disjoint › True at initialization and Union won’t modify the fact for remaining trees • Trees form equivalent classes under the relation “is connected to” › u connected to u (reflexivity) › u connected to v implies v connected to u (symmetry) › u connected to v and v connected to w implies a path from u to w so u connected to w (transitivity)
  • 17. 6/13/2023 CSE 373 AU 04 - Minimum Spanning Trees 17 K’s Algorithm Data Structures • Adjacency list for the graph › To perform the initialization of the data structures below • Disjoint Set ADT’s for the trees (recall Up tree implementation of Union-Find) • Binary heap for edges
  • 18. 6/13/2023 CSE 373 AU 04 - Minimum Spanning Trees 18 Example 1 2 3 4 6 5 10 1 5 8 3 1 1 6 2 4 1
  • 19. 6/13/2023 CSE 373 AU 04 - Minimum Spanning Trees 19 1 2 3 4 6 5 10 1 5 8 3 1 1 6 2 4 1
  • 20. 6/13/2023 CSE 373 AU 04 - Minimum Spanning Trees 20 Initialization 1 2 3 4 6 5 Initially, Forest of 6 trees F= {{1},{2},{3},{4},{5},{6}} Edges in a heap (not shown)
  • 21. 6/13/2023 CSE 373 AU 04 - Minimum Spanning Trees 21 Step 1 1 2 3 4 6 5 Select edge with lowest cost (2,5) Find(2) = 2, Find (5) = 5 Union(2,5) F= {{1},{2,5},{3},{4},{6}} 1 edge accepted 1
  • 22. 6/13/2023 CSE 373 AU 04 - Minimum Spanning Trees 22 Step 2 1 2 3 4 6 5 Select edge with lowest cost (2,6) Find(2) = 2, Find (6) = 6 Union(2,6) F= {{1},{2,5,6},{3},{4}} 2 edges accepted 1 1
  • 23. 6/13/2023 CSE 373 AU 04 - Minimum Spanning Trees 23 Step 3 1 2 3 4 6 5 Select edge with lowest cost (1,3) Find(1) = 1, Find (3) = 3 Union(1,3) F= {{1,3},{2,5,6},{4}} 3 edges accepted 1 1 1
  • 24. 6/13/2023 CSE 373 AU 04 - Minimum Spanning Trees 24 Step 4 1 2 3 4 6 5 Select edge with lowest cost (5,6) Find(5) = 2, Find (6) = 2 Do nothing F= {{1,3},{2,5,6},{4}} 3 edges accepted 1 1 1
  • 25. 6/13/2023 CSE 373 AU 04 - Minimum Spanning Trees 25 Step 5 1 2 3 4 6 5 Select edge with lowest cost (3,4) Find(3) = 1, Find (4) = 4 Union(1,4) F= {{1,3,4},{2,5,6}} 4 edges accepted 1 1 1 3
  • 26. 6/13/2023 CSE 373 AU 04 - Minimum Spanning Trees 26 Step 6 1 2 3 4 6 5 Select edge with lowest cost (4,5) Find(4) = 1, Find (5) = 2 Union(1,2) F= {{1,3,4,2,5,6}} 5 edges accepted : end Total cost = 10 Although there is a unique spanning tree in this example, this is not generally the case 1 1 1 3 4
  • 27. 6/13/2023 CSE 373 AU 04 - Minimum Spanning Trees 27 Kruskal’s Algorithm Analysis • Initialize forest O(n) • Initialize heap O(m), m = |E| • Loop performed m times › In the loop one DeleteMin O(log m) › Two Find, each O(log n) › One Union (at most) O(1) • So worst case O(m log m) = O(m log n)
  • 28. 6/13/2023 CSE 373 AU 04 - Minimum Spanning Trees 28 Time Complexity Summary • Recall that m = |E| = O(V2) = O(n2 ) • Prim’s runs in O((n+m) log n) • Kruskal runs in O(m log m) = O(m log n) • In practice, Kruskal has a tendency to run faster since graphs might not be dense and not all edges need to be looked at in the Deletemin operations