SlideShare a Scribd company logo
Introduction
A graph problem is given a set of vertices and (weighted) edges, find a
subset of edges that connects all the vertices and has minimum total weight giving a
minimum spanning tree (MST). An example of such a problem is determining the
minimum amount of copper needed to produce a common ground in an electronic
circuit. There are two well known algorithms for solving MST problems - Kruskal's
algorithm and Prim's algorithm.
4.2.1. Minimum Spanning Trees
Problem
Given a connected, undirected graph G(V,E) with weighted edges w(u,v),
find an acyclic subset of edges T ⊆ E that connect (or span) all the vertices and has
minumum total weight, i.e.
We call T a minimum spanning tree of G. While the value w(T) is unique, the tree
itself may not be.
Generic Algorithm
If A is a subset of an MST, then a safe edge is one such that
A' = A ∪ (u,v)
is also a subset of an MST.
We can then find an MST by beginning with any vertex and adding safe
edges until A' forms a spanning tree. This tree will contain |V| - 1 edges and be a
mininum spanning tree. Hence we simply need a way to determine safe edges.
A cut is a partition of V into two subsets {S} and {V-S}. An edge crosses the
cut if one vertex is in {S} and the other is in {V-S}. A set of edges A, respects a cut
if none of the edges in A crosses the cut. A light edge is an edge that crosses a cut
with minimum weight.
Using these definitions, we can prove the following theorem:
Given a connected, undirected graph G(V,E) with edge weights w(u,v)
If A is a subset of an MST, for any cut that respects A ⇒ a light edge is a safe edge
for A. (Note the converse is not true.)
An immediate corrolary is that if we have a forest of connected components (trees)
each with a set of minimum spanning edges, then any light edge between the trees is
a safe edge. Hence we can grow the MST by simply adding |V| - 1 light edges
between subsets of the MST.
4.2.2. Kruskal's Algorithm
A simple way to implement the generic algorithm is to grow the MST by
adding edges between trees in the forest in order of increasing weights until all trees
are connected. This approach is known as Kruskal's algorithm.
Algorithm
MST-KRUSKAL(G,w)
1. A = ∅
2. for each vertex v ∈ G.V
3. MAKE-SET(v)
4. sort the edges of G.E into nondecreasing order by weight w
5. for each edge (u,v) ∈ G.E, taken in nondecreasing order by weight
6. if FIND-SET(u) ≠ FIND-SET(v)
7. A = A ∪ {(u,v)}
8. UNION(u,v)
9. return A
Basically the algorithm works as follows:
1. Make each vertex a separate tree
2. Sort the edges in nondecreasing order
3. Add an edge if it connects different trees and merge the trees together
The run time of Kruskal's algorithm depends on the implementation of the set
operations, but can be made to run in O(E log V).
Example
Given the following undirected graph
We first make each vertex a separate tree and sort the edges in no decreasing order
Step 1: Add edge (u1,u3) and merge u1 and u3
Step 2: Add edge (u2,u5) and merge u2 and u5
Step 3: Add edge (u1,u2) and merge the tree from step 1 with the tree from step 2
Step 4: Add edge (u3,u4) (note edge (u2,u3) does not connect separate trees) and
merge u4
The final edge (u1,u4) does not connect separate trees. Thus the final MST is
With total weight 11.
An alternative algorithm for finding MST's is Prim's algorithm which runs
asymptotically faster than Kruskal's algorithm, but at the price of requiring a queue
data structure.
4.2.3. Prim's Algorithm
Prim's algorithm finds MST's by growing the MST by adding light edges
between the current tree and other vertices. The vertices are stored in a minimum
priority queue based on the smallest weigh edge connecting vertices currently not
in the tree with a vertex in the tree.
Algorithm
MST-PRIM(G,w,r)
1. for each u ∈ G.V
2. u.key = ∞
3. u.pi = NIL
4. r.key = 0
5. Q = G.V
6. while Q ≠ ∅
7. u = EXTRACT-MIN(Q)
8. for each v ∈ G.Adj[u]
9. if v ∈ Q and w(u,v) < v.key
10. v.pi = u
11. v.key = w(u,v)
Basically the algorithm works as follows:
1. Initialize Q and set the source (root) key to 0
2. While Q is not empty, dequeue the vertex with minimum weight edge and
add it to the tree by adding edge (u.π,u) to T
3. For each vertex v in Adj[u] that is still in Q, check if w(u,v) (the edge
weights from u for all vertices not in T) are less than the current v.key (the
current smallest edge weight) and if so update the predecessor and key
fields
The run time of Prim's algorithm depends on the implementation of the priority
queue, but can be made to run in O(E + V lg V) using a Fibonacci heap for the
priority queue.
Example
Using the same undirected graph from here
We will (arbitrarily) initialize Q with vertex 1 giving
Step 1: Dequeue vertex 1 and update Q (and reprioritizing) by changing u3.key = 2
(edge (u1,u3)), u2.key = 3 (edge (u1,u2)), u4.key = 6 (edge (u1,u4))
Step 2: Dequeue vertex 3 (adding edge (u1,u3) to T) and update Q (and
reprioritizing) by changing u4.key = 4 (edge (u3,u4))
Step 3: Dequeue vertex 2 (adding edge (u1,u2) to T) and update Q (and
reprioritizing) by changing u5.key = 2 (edge (u2,u5))
Step 4: Dequeue vertex 5 (adding edge (u2,u5) to T) with no updates to Q
Step 5: Dequeue vertex 4 (adding edge (u3,u4) to T) with no updates to Q
At this point Q = ∅ giving the final MST
With total weight 11.

More Related Content

What's hot

Sets and disjoint sets union123
Sets and disjoint sets union123Sets and disjoint sets union123
Sets and disjoint sets union123
Ankita Goyal
 

What's hot (20)

ADA - Minimum Spanning Tree Prim Kruskal and Dijkstra
ADA - Minimum Spanning Tree Prim Kruskal and Dijkstra ADA - Minimum Spanning Tree Prim Kruskal and Dijkstra
ADA - Minimum Spanning Tree Prim Kruskal and Dijkstra
 
Lecture 6 disjoint set
Lecture 6 disjoint setLecture 6 disjoint set
Lecture 6 disjoint set
 
Disjoint set
Disjoint setDisjoint set
Disjoint set
 
Neil Lambert - From D-branes to M-branes
Neil Lambert - From D-branes to M-branesNeil Lambert - From D-branes to M-branes
Neil Lambert - From D-branes to M-branes
 
IRJET - On Strong Blast Domination of Graphs
 IRJET - On Strong Blast Domination of Graphs IRJET - On Strong Blast Domination of Graphs
IRJET - On Strong Blast Domination of Graphs
 
Bounds on inverse domination in squares of graphs
Bounds on inverse domination in squares of graphsBounds on inverse domination in squares of graphs
Bounds on inverse domination in squares of graphs
 
07. disjoint set
07. disjoint set07. disjoint set
07. disjoint set
 
Sets and disjoint sets union123
Sets and disjoint sets union123Sets and disjoint sets union123
Sets and disjoint sets union123
 
20 Single Source Shorthest Path
20 Single Source Shorthest Path20 Single Source Shorthest Path
20 Single Source Shorthest Path
 
Eh2 piezoelectric energy harvesting due to harmonic excitations
Eh2   piezoelectric energy harvesting due to harmonic excitationsEh2   piezoelectric energy harvesting due to harmonic excitations
Eh2 piezoelectric energy harvesting due to harmonic excitations
 
prim's and kruskal's algorithm
prim's and kruskal's algorithmprim's and kruskal's algorithm
prim's and kruskal's algorithm
 
Phase transition and casimir effect
Phase transition and casimir effectPhase transition and casimir effect
Phase transition and casimir effect
 
Superconductivity and Spin Density Wave (SDW) in NaFe1-xCoxAs
Superconductivity and Spin Density Wave (SDW) in NaFe1-xCoxAsSuperconductivity and Spin Density Wave (SDW) in NaFe1-xCoxAs
Superconductivity and Spin Density Wave (SDW) in NaFe1-xCoxAs
 
17 prims-kruskals (1)
17 prims-kruskals (1)17 prims-kruskals (1)
17 prims-kruskals (1)
 
PhotonModel
PhotonModelPhotonModel
PhotonModel
 
Shortest route and mst
Shortest route and mstShortest route and mst
Shortest route and mst
 
Very brief highlights on some key details 2
Very brief highlights on some key details 2Very brief highlights on some key details 2
Very brief highlights on some key details 2
 
EH1 - Reduced-order modelling for vibration energy harvesting
EH1 - Reduced-order modelling for vibration energy harvestingEH1 - Reduced-order modelling for vibration energy harvesting
EH1 - Reduced-order modelling for vibration energy harvesting
 
Eh3 analysis of nonlinear energy harvesters
Eh3   analysis of nonlinear energy harvestersEh3   analysis of nonlinear energy harvesters
Eh3 analysis of nonlinear energy harvesters
 
Complimentary Energy Method in structural analysis
Complimentary Energy Method in structural analysisComplimentary Energy Method in structural analysis
Complimentary Energy Method in structural analysis
 

Similar to Daa chapter13

lecture 16
lecture 16lecture 16
lecture 16
sajinsc
 
Algorithm Design and Complexity - Course 9
Algorithm Design and Complexity - Course 9Algorithm Design and Complexity - Course 9
Algorithm Design and Complexity - Course 9
Traian Rebedea
 
Algorithm chapter 9
Algorithm chapter 9Algorithm chapter 9
Algorithm chapter 9
chidabdu
 
spanningtreesapplications-120903115339-phpapp02 (1).pdf
spanningtreesapplications-120903115339-phpapp02 (1).pdfspanningtreesapplications-120903115339-phpapp02 (1).pdf
spanningtreesapplications-120903115339-phpapp02 (1).pdf
YasirAli74993
 

Similar to Daa chapter13 (20)

minimum spanning trees Algorithm
minimum spanning trees Algorithm minimum spanning trees Algorithm
minimum spanning trees Algorithm
 
lecture 16
lecture 16lecture 16
lecture 16
 
Algorithm Design and Complexity - Course 9
Algorithm Design and Complexity - Course 9Algorithm Design and Complexity - Course 9
Algorithm Design and Complexity - Course 9
 
Chapter 24 aoa
Chapter 24 aoaChapter 24 aoa
Chapter 24 aoa
 
19 Minimum Spanning Trees
19 Minimum Spanning Trees19 Minimum Spanning Trees
19 Minimum Spanning Trees
 
MST
MSTMST
MST
 
Ijciras1101
Ijciras1101Ijciras1101
Ijciras1101
 
A NEW PARALLEL ALGORITHM FOR COMPUTING MINIMUM SPANNING TREE
A NEW PARALLEL ALGORITHM FOR COMPUTING MINIMUM SPANNING TREEA NEW PARALLEL ALGORITHM FOR COMPUTING MINIMUM SPANNING TREE
A NEW PARALLEL ALGORITHM FOR COMPUTING MINIMUM SPANNING TREE
 
A NEW PARALLEL ALGORITHM FOR COMPUTING MINIMUM SPANNING TREE
A NEW PARALLEL ALGORITHM FOR COMPUTING MINIMUM SPANNING TREEA NEW PARALLEL ALGORITHM FOR COMPUTING MINIMUM SPANNING TREE
A NEW PARALLEL ALGORITHM FOR COMPUTING MINIMUM SPANNING TREE
 
8_MST_pptx.pptx
8_MST_pptx.pptx8_MST_pptx.pptx
8_MST_pptx.pptx
 
test pre
test pretest pre
test pre
 
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
 
Daa chpater14
Daa chpater14Daa chpater14
Daa chpater14
 
Algorithm chapter 9
Algorithm chapter 9Algorithm chapter 9
Algorithm chapter 9
 
Data structure
Data structureData structure
Data structure
 
project final
project finalproject final
project final
 
5.1 greedy 03
5.1 greedy 035.1 greedy 03
5.1 greedy 03
 
Data structure
Data structureData structure
Data structure
 
Applied Graph Theory Applications
Applied Graph Theory ApplicationsApplied Graph Theory Applications
Applied Graph Theory Applications
 
spanningtreesapplications-120903115339-phpapp02 (1).pdf
spanningtreesapplications-120903115339-phpapp02 (1).pdfspanningtreesapplications-120903115339-phpapp02 (1).pdf
spanningtreesapplications-120903115339-phpapp02 (1).pdf
 

More from B.Kirron Reddi (17)

What after graduation_-_mba
What after graduation_-_mbaWhat after graduation_-_mba
What after graduation_-_mba
 
What after graduation_-_banks
What after graduation_-_banksWhat after graduation_-_banks
What after graduation_-_banks
 
What after graduation_-_mca
What after graduation_-_mcaWhat after graduation_-_mca
What after graduation_-_mca
 
Daa chpater 12
Daa chpater 12Daa chpater 12
Daa chpater 12
 
Daa chapter11
Daa chapter11Daa chapter11
Daa chapter11
 
Daa chapter10
Daa chapter10Daa chapter10
Daa chapter10
 
Daa chapter9
Daa chapter9Daa chapter9
Daa chapter9
 
Daa chapter8
Daa chapter8Daa chapter8
Daa chapter8
 
Daa chapter7
Daa chapter7Daa chapter7
Daa chapter7
 
Daa chapter6
Daa chapter6Daa chapter6
Daa chapter6
 
Daa chapter5
Daa chapter5Daa chapter5
Daa chapter5
 
Daa chapter4
Daa chapter4Daa chapter4
Daa chapter4
 
Daa chapter 3
Daa chapter 3Daa chapter 3
Daa chapter 3
 
Daa chapter 2
Daa chapter 2Daa chapter 2
Daa chapter 2
 
Daa chapter 1
Daa chapter 1Daa chapter 1
Daa chapter 1
 
Daa contents by B.Kirron Reddi
Daa contents by B.Kirron ReddiDaa contents by B.Kirron Reddi
Daa contents by B.Kirron Reddi
 
Searching and sorting by B kirron Reddi
Searching and sorting by B kirron ReddiSearching and sorting by B kirron Reddi
Searching and sorting by B kirron Reddi
 

Recently uploaded

Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 

Recently uploaded (20)

The Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational ResourcesThe Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational Resources
 
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptxslides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
 
Application of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matricesApplication of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matrices
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
NLC-2024-Orientation-for-RO-SDO (1).pptx
NLC-2024-Orientation-for-RO-SDO (1).pptxNLC-2024-Orientation-for-RO-SDO (1).pptx
NLC-2024-Orientation-for-RO-SDO (1).pptx
 
Basic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
Basic Civil Engg Notes_Chapter-6_Environment Pollution & EngineeringBasic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
Basic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
 
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
 
Forest and Wildlife Resources Class 10 Free Study Material PDF
Forest and Wildlife Resources Class 10 Free Study Material PDFForest and Wildlife Resources Class 10 Free Study Material PDF
Forest and Wildlife Resources Class 10 Free Study Material PDF
 
Salient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptxSalient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptx
 
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.pptBasic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
 
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxMatatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
 
Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"
Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"
Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfDanh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptxSolid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
B.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdfB.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdf
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 

Daa chapter13

  • 1. Introduction A graph problem is given a set of vertices and (weighted) edges, find a subset of edges that connects all the vertices and has minimum total weight giving a minimum spanning tree (MST). An example of such a problem is determining the minimum amount of copper needed to produce a common ground in an electronic circuit. There are two well known algorithms for solving MST problems - Kruskal's algorithm and Prim's algorithm. 4.2.1. Minimum Spanning Trees Problem Given a connected, undirected graph G(V,E) with weighted edges w(u,v), find an acyclic subset of edges T ⊆ E that connect (or span) all the vertices and has minumum total weight, i.e. We call T a minimum spanning tree of G. While the value w(T) is unique, the tree itself may not be. Generic Algorithm If A is a subset of an MST, then a safe edge is one such that A' = A ∪ (u,v) is also a subset of an MST. We can then find an MST by beginning with any vertex and adding safe edges until A' forms a spanning tree. This tree will contain |V| - 1 edges and be a mininum spanning tree. Hence we simply need a way to determine safe edges. A cut is a partition of V into two subsets {S} and {V-S}. An edge crosses the cut if one vertex is in {S} and the other is in {V-S}. A set of edges A, respects a cut if none of the edges in A crosses the cut. A light edge is an edge that crosses a cut with minimum weight. Using these definitions, we can prove the following theorem: Given a connected, undirected graph G(V,E) with edge weights w(u,v)
  • 2. If A is a subset of an MST, for any cut that respects A ⇒ a light edge is a safe edge for A. (Note the converse is not true.) An immediate corrolary is that if we have a forest of connected components (trees) each with a set of minimum spanning edges, then any light edge between the trees is a safe edge. Hence we can grow the MST by simply adding |V| - 1 light edges between subsets of the MST. 4.2.2. Kruskal's Algorithm A simple way to implement the generic algorithm is to grow the MST by adding edges between trees in the forest in order of increasing weights until all trees are connected. This approach is known as Kruskal's algorithm. Algorithm MST-KRUSKAL(G,w) 1. A = ∅ 2. for each vertex v ∈ G.V 3. MAKE-SET(v) 4. sort the edges of G.E into nondecreasing order by weight w 5. for each edge (u,v) ∈ G.E, taken in nondecreasing order by weight 6. if FIND-SET(u) ≠ FIND-SET(v) 7. A = A ∪ {(u,v)} 8. UNION(u,v) 9. return A Basically the algorithm works as follows: 1. Make each vertex a separate tree 2. Sort the edges in nondecreasing order 3. Add an edge if it connects different trees and merge the trees together The run time of Kruskal's algorithm depends on the implementation of the set operations, but can be made to run in O(E log V). Example Given the following undirected graph
  • 3. We first make each vertex a separate tree and sort the edges in no decreasing order Step 1: Add edge (u1,u3) and merge u1 and u3 Step 2: Add edge (u2,u5) and merge u2 and u5 Step 3: Add edge (u1,u2) and merge the tree from step 1 with the tree from step 2
  • 4. Step 4: Add edge (u3,u4) (note edge (u2,u3) does not connect separate trees) and merge u4 The final edge (u1,u4) does not connect separate trees. Thus the final MST is With total weight 11. An alternative algorithm for finding MST's is Prim's algorithm which runs asymptotically faster than Kruskal's algorithm, but at the price of requiring a queue data structure.
  • 5. 4.2.3. Prim's Algorithm Prim's algorithm finds MST's by growing the MST by adding light edges between the current tree and other vertices. The vertices are stored in a minimum priority queue based on the smallest weigh edge connecting vertices currently not in the tree with a vertex in the tree. Algorithm MST-PRIM(G,w,r) 1. for each u ∈ G.V 2. u.key = ∞ 3. u.pi = NIL 4. r.key = 0 5. Q = G.V 6. while Q ≠ ∅ 7. u = EXTRACT-MIN(Q) 8. for each v ∈ G.Adj[u] 9. if v ∈ Q and w(u,v) < v.key 10. v.pi = u 11. v.key = w(u,v) Basically the algorithm works as follows: 1. Initialize Q and set the source (root) key to 0 2. While Q is not empty, dequeue the vertex with minimum weight edge and add it to the tree by adding edge (u.π,u) to T 3. For each vertex v in Adj[u] that is still in Q, check if w(u,v) (the edge weights from u for all vertices not in T) are less than the current v.key (the current smallest edge weight) and if so update the predecessor and key fields The run time of Prim's algorithm depends on the implementation of the priority queue, but can be made to run in O(E + V lg V) using a Fibonacci heap for the priority queue. Example Using the same undirected graph from here
  • 6. We will (arbitrarily) initialize Q with vertex 1 giving Step 1: Dequeue vertex 1 and update Q (and reprioritizing) by changing u3.key = 2 (edge (u1,u3)), u2.key = 3 (edge (u1,u2)), u4.key = 6 (edge (u1,u4)) Step 2: Dequeue vertex 3 (adding edge (u1,u3) to T) and update Q (and reprioritizing) by changing u4.key = 4 (edge (u3,u4))
  • 7. Step 3: Dequeue vertex 2 (adding edge (u1,u2) to T) and update Q (and reprioritizing) by changing u5.key = 2 (edge (u2,u5)) Step 4: Dequeue vertex 5 (adding edge (u2,u5) to T) with no updates to Q Step 5: Dequeue vertex 4 (adding edge (u3,u4) to T) with no updates to Q
  • 8. At this point Q = ∅ giving the final MST With total weight 11.