SlideShare a Scribd company logo
1 of 23
Data Structures
Lecture 28: Minimum Spanning Tree
Outlines
 Minimum Spanning Tree
 Prim’s Algorithm
 Kruskal’s Algorithm
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Minimum Spanning Tree
 Input: A connected, undirected graph G = (V, E)
with weight function w : E R.
• For simplicity, we assume that all edge weights are
distinct.
• Output: A spanning tree T, a tree that connects all
vertices, of minimum weight:
Tvu
vuwTw
),(
),()(
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Example of MST
6 12
5
14
3
8
10
15
9
7
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Prim’s Algorithm
IDEA: Maintain V – A as a priority queue Q. Key
each vertex in Q with the weight of the least-
weight edge connecting it to a vertex in A.
Q V
key[v] for all v V
key[s] 0 for some arbitrary s V
while Q
do u EXTRACT-MIN(Q)
for each v Adj[u]
do if v Q and w(u, v) < key[v]
then key[v] w(u, v) ⊳ DECREASE-KEY
[v] u
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Example of Prim’s algorithm
A
V – A
0
6 12
5
14
3
8
10
15
9
7
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Example of Prim’s algorithm
A
V – A
0
6 12
5
14
3
8
10
15
9
7
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Example of Prim’s algorithm
A
V – A
0
6 12
5
14
3
8
10
15
9
7
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Example of Prim’s algorithm
A
V – A
7
0
6 12
5
14
3
8
10
15
9
7
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Example of Prim’s algorithm
A
V – A
7
0
6 12
5
14
3
8
10
15
9
7
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Example of Prim’s algorithm
A
V – A
5 7
0
6 12
5
14
3
8
10
15
9
7
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Example of Prim’s algorithm
A
V – A
5 7
0
6 12
5
14
3
8
10
15
9
7
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Example of Prim’s algorithm
A
V – A
6
5 7
0
6 12
5
14
3
8
10
15
9
7
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Example of Prim’s algorithm
A
V – A
6
5 7
0
8
6 12
5
14
3
8
10
15
9
7
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Example of Prim’s algorithm
A
V – A
6
5 7
0
8
6 12
5
14
3
8
10
15
9
7
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Example of Prim’s algorithm
A
V – A
6
5 7
3 0
8
6 12
5
14
3
8
10
15
9
7
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Example of Prim’s algorithm
A
V – A
6
5 7
3 0
8
9
6 12
5
14
3
8
10
15
9
7
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Example of Prim’s algorithm
A
V – A
6
5 7
3 0
8
9
15
6 12
5
14
3
8
10
15
9
7
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Kruskal’s Algorithm
It is a greedy algorithm.
 In Kruskal’s algorithm, the set A is a forest.
 The safe edge is added to A is always a least-weight edge in the
graph that connects two distinct Components.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Kruskal’s Algorithm
 The operation FIND-SET(u) returns a representative element
from the set that contains u.
 Thus we can determine whether two vertices u and v belong to
the same tree by testing whether
FIND-SET(u) = FIND-SET(v)
 The combining of trees is accomplished by the
UNION procedure
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Kruskal’s Algorithm
1. A
2. for each vertex v V[G]
3.do MAKE-SET(v)
4.short the edges of E into non-decreasing order
by weight.
5.for each edge (u, v) E, taken in non-decreasing order
by weight.
6.do if FIND-SET(u) != FIND-SET(v)
7. then, A  A U {(u, v)}
8. UNION(u, v)
9.return A
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Complexity
Prim’s Algorithm: O(E logV)
Kruskal’s Algorithm: O(E logV)
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)

More Related Content

Viewers also liked

Minimum Spanning Tree
Minimum Spanning TreeMinimum Spanning Tree
Minimum Spanning Treezhaokatherine
 
Prim's Algorithm on minimum spanning tree
Prim's Algorithm on minimum spanning treePrim's Algorithm on minimum spanning tree
Prim's Algorithm on minimum spanning treeoneous
 
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 Sahil Kumar
 
Disk scheduling algorithms
Disk scheduling algorithms Disk scheduling algorithms
Disk scheduling algorithms Paresh Parmar
 
My presentation minimum spanning tree
My presentation minimum spanning treeMy presentation minimum spanning tree
My presentation minimum spanning treeAlona Salva
 
Spanning trees & applications
Spanning trees & applicationsSpanning trees & applications
Spanning trees & applicationsTech_MX
 
Kruskals prims shared by: geekssay.com
Kruskals prims shared by: geekssay.comKruskals prims shared by: geekssay.com
Kruskals prims shared by: geekssay.comHemant Gautam
 
Prim Algorithm and kruskal algorithm
Prim Algorithm and kruskal algorithmPrim Algorithm and kruskal algorithm
Prim Algorithm and kruskal algorithmAcad
 
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
 
A presentation on prim's and kruskal's algorithm
A presentation on prim's and kruskal's algorithmA presentation on prim's and kruskal's algorithm
A presentation on prim's and kruskal's algorithmGaurav Kolekar
 
Prims Algorithm
Prims AlgorithmPrims Algorithm
Prims AlgorithmSriram Raj
 
Kruskal & Prim's Algorithm
Kruskal & Prim's AlgorithmKruskal & Prim's Algorithm
Kruskal & Prim's AlgorithmIfad Rahman
 
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)Mohanlal Sukhadia University (MLSU)
 
Minimum spanning tree algorithms by ibrahim_alfayoumi
Minimum spanning tree algorithms by ibrahim_alfayoumiMinimum spanning tree algorithms by ibrahim_alfayoumi
Minimum spanning tree algorithms by ibrahim_alfayoumiIbrahim Alfayoumi
 

Viewers also liked (20)

Minimum Spanning Tree
Minimum Spanning TreeMinimum Spanning Tree
Minimum Spanning Tree
 
Minimum spanning Tree
Minimum spanning TreeMinimum spanning Tree
Minimum spanning Tree
 
9 cm402.18
9 cm402.189 cm402.18
9 cm402.18
 
Kruskal Algorithm
Kruskal AlgorithmKruskal Algorithm
Kruskal Algorithm
 
Prim's Algorithm on minimum spanning tree
Prim's Algorithm on minimum spanning treePrim's Algorithm on minimum spanning tree
Prim's Algorithm on minimum spanning tree
 
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
 
Minimum spanning tree
Minimum spanning treeMinimum spanning tree
Minimum spanning tree
 
Disk scheduling algorithms
Disk scheduling algorithms Disk scheduling algorithms
Disk scheduling algorithms
 
My presentation minimum spanning tree
My presentation minimum spanning treeMy presentation minimum spanning tree
My presentation minimum spanning tree
 
Spanning trees & applications
Spanning trees & applicationsSpanning trees & applications
Spanning trees & applications
 
Kruskals prims shared by: geekssay.com
Kruskals prims shared by: geekssay.comKruskals prims shared by: geekssay.com
Kruskals prims shared by: geekssay.com
 
Prim Algorithm and kruskal algorithm
Prim Algorithm and kruskal algorithmPrim Algorithm and kruskal algorithm
Prim Algorithm and kruskal algorithm
 
Greedy minimum spanning tree- prim's algorithm
Greedy minimum spanning tree- prim's algorithmGreedy minimum spanning tree- prim's algorithm
Greedy minimum spanning tree- prim's algorithm
 
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
 
A presentation on prim's and kruskal's algorithm
A presentation on prim's and kruskal's algorithmA presentation on prim's and kruskal's algorithm
A presentation on prim's and kruskal's algorithm
 
Prims Algorithm
Prims AlgorithmPrims Algorithm
Prims Algorithm
 
Kruskal & Prim's Algorithm
Kruskal & Prim's AlgorithmKruskal & Prim's Algorithm
Kruskal & Prim's Algorithm
 
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
 
Greedy Algorithms with examples' b-18298
Greedy Algorithms with examples'  b-18298Greedy Algorithms with examples'  b-18298
Greedy Algorithms with examples' b-18298
 
Minimum spanning tree algorithms by ibrahim_alfayoumi
Minimum spanning tree algorithms by ibrahim_alfayoumiMinimum spanning tree algorithms by ibrahim_alfayoumi
Minimum spanning tree algorithms by ibrahim_alfayoumi
 

Recently uploaded

psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesShubhangi Sonawane
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfChris Hunter
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIShubhangi Sonawane
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 

Recently uploaded (20)

psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 

Minimum spanning tree

  • 1. Data Structures Lecture 28: Minimum Spanning Tree
  • 2. Outlines  Minimum Spanning Tree  Prim’s Algorithm  Kruskal’s Algorithm Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 3. Minimum Spanning Tree  Input: A connected, undirected graph G = (V, E) with weight function w : E R. • For simplicity, we assume that all edge weights are distinct. • Output: A spanning tree T, a tree that connects all vertices, of minimum weight: Tvu vuwTw ),( ),()( Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 4. Example of MST 6 12 5 14 3 8 10 15 9 7 Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 5. Prim’s Algorithm IDEA: Maintain V – A as a priority queue Q. Key each vertex in Q with the weight of the least- weight edge connecting it to a vertex in A. Q V key[v] for all v V key[s] 0 for some arbitrary s V while Q do u EXTRACT-MIN(Q) for each v Adj[u] do if v Q and w(u, v) < key[v] then key[v] w(u, v) ⊳ DECREASE-KEY [v] u Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 6. Example of Prim’s algorithm A V – A 0 6 12 5 14 3 8 10 15 9 7 Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 7. Example of Prim’s algorithm A V – A 0 6 12 5 14 3 8 10 15 9 7 Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 8. Example of Prim’s algorithm A V – A 0 6 12 5 14 3 8 10 15 9 7 Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 9. Example of Prim’s algorithm A V – A 7 0 6 12 5 14 3 8 10 15 9 7 Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 10. Example of Prim’s algorithm A V – A 7 0 6 12 5 14 3 8 10 15 9 7 Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 11. Example of Prim’s algorithm A V – A 5 7 0 6 12 5 14 3 8 10 15 9 7 Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 12. Example of Prim’s algorithm A V – A 5 7 0 6 12 5 14 3 8 10 15 9 7 Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 13. Example of Prim’s algorithm A V – A 6 5 7 0 6 12 5 14 3 8 10 15 9 7 Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 14. Example of Prim’s algorithm A V – A 6 5 7 0 8 6 12 5 14 3 8 10 15 9 7 Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 15. Example of Prim’s algorithm A V – A 6 5 7 0 8 6 12 5 14 3 8 10 15 9 7 Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 16. Example of Prim’s algorithm A V – A 6 5 7 3 0 8 6 12 5 14 3 8 10 15 9 7 Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 17. Example of Prim’s algorithm A V – A 6 5 7 3 0 8 9 6 12 5 14 3 8 10 15 9 7 Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 18. Example of Prim’s algorithm A V – A 6 5 7 3 0 8 9 15 6 12 5 14 3 8 10 15 9 7 Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 19. Kruskal’s Algorithm It is a greedy algorithm.  In Kruskal’s algorithm, the set A is a forest.  The safe edge is added to A is always a least-weight edge in the graph that connects two distinct Components. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 20. Kruskal’s Algorithm  The operation FIND-SET(u) returns a representative element from the set that contains u.  Thus we can determine whether two vertices u and v belong to the same tree by testing whether FIND-SET(u) = FIND-SET(v)  The combining of trees is accomplished by the UNION procedure Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 21. Kruskal’s Algorithm 1. A 2. for each vertex v V[G] 3.do MAKE-SET(v) 4.short the edges of E into non-decreasing order by weight. 5.for each edge (u, v) E, taken in non-decreasing order by weight. 6.do if FIND-SET(u) != FIND-SET(v) 7. then, A  A U {(u, v)} 8. UNION(u, v) 9.return A Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 22. Complexity Prim’s Algorithm: O(E logV) Kruskal’s Algorithm: O(E logV) Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 23. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)