SlideShare a Scribd company logo
Minimum spanning trees
Minimum Connector Algorithms


        Kruskal’s algorithm                       Prim’s algorithm

1.   Select the shortest edge in a      1.   Select any vertex
     network
                                        2.   Select the shortest edge
2.   Select the next shortest edge           connected to that vertex
     which does not create a cycle
                                        3.   Select the shortest edge
3.   Repeat step 2 until all vertices        connected to any vertex
     have been connected                     already connected

                                        4.   Repeat step 3 until all
                                             vertices have been
                                             connected
Example
 A cable company want to connect five villages to
 their network    which currently extends to the
 market town of Avonford. What is the minimum
 length of cable needed?
            Brinleigh         5                 Cornwell

             3
                                                    4
                         8             6

                                        8
 Avonford                         Fingley                  Donster
                     7
                               5
                 4                          2

                             Edan
We model the situation as a network, then the
problem is to find the minimum connector for the
network

                 B           5               C

         3
                                                 4
                     8               6

                                      8
    A                            F                   D
                 7
                              5
             4                           2

                         E
Kruskal’s Algorithm
                                                    List the edges in
                                                    order of size:
            B           5               C           ED   2
                                                    AB   3
    3                                               AE   4
                                            4
                8               6                   CD   4
                                                    BC   5
                                 8                  EF   5
A                                               D   CF   6
            7               F
                                                    AF   7
                         5                          BF   8
        4                                           CF   8
                                    2


                    E
Kruskal’s Algorithm

                                                    Select the shortest
                                                    edge in the network
            B           5               C
                                                    ED 2
    3
                                            4
                8               6

                                 8
A                                               D
            7               F

                         5
        4                           2


                    E
Kruskal’s Algorithm
                                                    Select the next shortest
                                                    edge which does not
            B           5                           create a cycle
                                        C
                                                    ED 2
    3                                               AB 3
                                            4
                8               6

                                 8
A                                               D
            7               F

                         5
        4                           2


                    E
Kruskal’s Algorithm
                                                    Select the next shortest
                                                    edge which does not
            B           5                           create a cycle
                                        C
                                                    ED 2
    3                                               AB 3
                                            4
                8               6                   CD 4 (or AE 4)

                                 8
A                                               D
            7               F

                         5
        4                           2


                    E
Kruskal’s Algorithm
                                                    Select the next shortest
                                                    edge which does not
            B           5                           create a cycle
                                        C
                                                    ED   2
    3                                               AB   3
                                            4
                8               6                   CD   4
                                                    AE   4
                                 8
A                                               D
            7               F

                         5
        4                           2


                    E
Kruskal’s Algorithm
                                                    Select the next shortest
                                                    edge which does not
            B           5                           create a cycle
                                        C
                                                    ED   2
    3                                               AB   3
                                            4
                8               6                   CD   4
                                                    AE   4
                                 8                  BC   5 – forms a cycle
A                                               D   EF   5
            7               F

                         5
        4                           2


                    E
Kruskal’s Algorithm
                                                    All vertices have been
                                                    connected.
            B           5               C           The solution is
    3                                               ED   2
                                            4
                8               6                   AB   3
                                                    CD   4
                                 8                  AE   4
A                                               D   EF   5
            7               F

                         5
        4                                           Total weight of tree: 18
                                    2


                    E
Prim’s Algorithm
                                                    Select any vertex

            B           5                           A
                                        C
                                                    Select the shortest
    3                                               edge connected to
                                            4
                8               6                   that vertex

                                 8                  AB 3
A                                               D
            7               F

                         5
        4                           2


                    E
Prim’s Algorithm
                                                    Select the shortest
                                                    edge connected to
            B           5                           any vertex already
                                        C           connected.
    3                                               AE 4
                                            4
                8               6

                                 8
A                                               D
            7               F

                         5
        4                           2


                    E
Prim’s Algorithm
                                                    Select the shortest
                                                    edge connected to
            B           5                           any vertex already
                                        C           connected.
    3                                               ED 2
                                            4
                8               6

                                 8
A                                               D
            7               F

                         5
        4                           2


                    E
Prim’s Algorithm
                                                    Select the shortest
                                                    edge connected to
            B           5                           any vertex already
                                        C           connected.
    3                                               DC 4
                                            4
                8               6

                                 8
A                                               D
            7               F

                         5
        4                           2


                    E
Prim’s Algorithm
                                                    Select the shortest
                                                    edge connected to
            B           5                           any vertex already
                                        C           connected.
    3                                               CB 5 – forms a cycle
                                            4
                8               6
                                                    EF 5
                                 8
A                                               D
            7               F

                         5
        4                           2


                    E
Prim’s Algorithm
                                                    All vertices have been
                                                    connected.
            B           5               C           The solution is
    3                                               ED   2
                                            4
                8               6                   AB   3
                                                    CD   4
                                 8                  AE   4
A                                               D   EF   5
            7               F

                         5
        4                                           Total weight of tree: 18
                                    2


                    E
Some points to note


•Both algorithms will always give solutions with the
same length.

•They will usually select edges in a different order
– you must show this in your workings.

•Occasionally they will use different edges – this
may happen when you have to choose between
edges with the same length. In this case there is
more than one minimum connector for the
network.

More Related Content

What's hot

19 primkruskal
19 primkruskal19 primkruskal
19 primkruskal
fika sweety
 
19 prim,kruskal alg. in data structure
19 prim,kruskal alg. in data structure19 prim,kruskal alg. in data structure
19 prim,kruskal alg. in data structure
EMEY GUJJAR
 
Radix sort concept
Radix sort conceptRadix sort concept
Radix sort concept
Zeeshan Ali
 
Kruskal Algorithm
Kruskal AlgorithmKruskal Algorithm
Kruskal Algorithm
Snehasis Panigrahi
 
[Question Paper] Electronic and Communication Technology (Revised Course) [Ja...
[Question Paper] Electronic and Communication Technology (Revised Course) [Ja...[Question Paper] Electronic and Communication Technology (Revised Course) [Ja...
[Question Paper] Electronic and Communication Technology (Revised Course) [Ja...
Mumbai B.Sc.IT Study
 
Minimum Spanning Tree
Minimum Spanning TreeMinimum Spanning Tree
Minimum Spanning Tree
Md. Shafiuzzaman Hira
 
Sorting2
Sorting2Sorting2
Sorting2
Saurabh Mishra
 
Single sourceshortestpath by emad
Single sourceshortestpath by emadSingle sourceshortestpath by emad
Single sourceshortestpath by emad
Kazi Emad
 
Mergesort
MergesortMergesort
Mergesort
SimoniShah6
 
Incremental Graph Queries for Cypher
Incremental Graph Queries for CypherIncremental Graph Queries for Cypher
Incremental Graph Queries for Cypher
openCypher
 
Unit 5 graphs minimum spanning trees
Unit 5   graphs minimum spanning treesUnit 5   graphs minimum spanning trees
Unit 5 graphs minimum spanning trees
kalyanineve
 
Range Minimum Queries
Range Minimum QueriesRange Minimum Queries
Range Minimum Queries
Benjamin Sach
 
Bellman ford algorithm
Bellman ford algorithmBellman ford algorithm
Bellman ford algorithm
A. S. M. Shafi
 
Network analysis
Network analysisNetwork analysis
Network analysis
Hakeem-Ur- Rehman
 
Lecture 15 ME 176 7 Root Locus Technique
Lecture 15 ME 176 7 Root Locus TechniqueLecture 15 ME 176 7 Root Locus Technique
Lecture 15 ME 176 7 Root Locus Technique
Leonides De Ocampo
 
Cee 312(6)(structural analysis)
Cee 312(6)(structural analysis)Cee 312(6)(structural analysis)
Cee 312(6)(structural analysis)
apudgr8
 
4.5 solve by finding square roots
4.5 solve by finding square roots4.5 solve by finding square roots
4.5 solve by finding square roots
Northside ISD
 
Lecture 16 data structures and algorithms
Lecture 16 data structures and algorithmsLecture 16 data structures and algorithms
Lecture 16 data structures and algorithms
Aakash deep Singhal
 

What's hot (18)

19 primkruskal
19 primkruskal19 primkruskal
19 primkruskal
 
19 prim,kruskal alg. in data structure
19 prim,kruskal alg. in data structure19 prim,kruskal alg. in data structure
19 prim,kruskal alg. in data structure
 
Radix sort concept
Radix sort conceptRadix sort concept
Radix sort concept
 
Kruskal Algorithm
Kruskal AlgorithmKruskal Algorithm
Kruskal Algorithm
 
[Question Paper] Electronic and Communication Technology (Revised Course) [Ja...
[Question Paper] Electronic and Communication Technology (Revised Course) [Ja...[Question Paper] Electronic and Communication Technology (Revised Course) [Ja...
[Question Paper] Electronic and Communication Technology (Revised Course) [Ja...
 
Minimum Spanning Tree
Minimum Spanning TreeMinimum Spanning Tree
Minimum Spanning Tree
 
Sorting2
Sorting2Sorting2
Sorting2
 
Single sourceshortestpath by emad
Single sourceshortestpath by emadSingle sourceshortestpath by emad
Single sourceshortestpath by emad
 
Mergesort
MergesortMergesort
Mergesort
 
Incremental Graph Queries for Cypher
Incremental Graph Queries for CypherIncremental Graph Queries for Cypher
Incremental Graph Queries for Cypher
 
Unit 5 graphs minimum spanning trees
Unit 5   graphs minimum spanning treesUnit 5   graphs minimum spanning trees
Unit 5 graphs minimum spanning trees
 
Range Minimum Queries
Range Minimum QueriesRange Minimum Queries
Range Minimum Queries
 
Bellman ford algorithm
Bellman ford algorithmBellman ford algorithm
Bellman ford algorithm
 
Network analysis
Network analysisNetwork analysis
Network analysis
 
Lecture 15 ME 176 7 Root Locus Technique
Lecture 15 ME 176 7 Root Locus TechniqueLecture 15 ME 176 7 Root Locus Technique
Lecture 15 ME 176 7 Root Locus Technique
 
Cee 312(6)(structural analysis)
Cee 312(6)(structural analysis)Cee 312(6)(structural analysis)
Cee 312(6)(structural analysis)
 
4.5 solve by finding square roots
4.5 solve by finding square roots4.5 solve by finding square roots
4.5 solve by finding square roots
 
Lecture 16 data structures and algorithms
Lecture 16 data structures and algorithmsLecture 16 data structures and algorithms
Lecture 16 data structures and algorithms
 

Viewers also liked

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
Department of Information Management Ming Chuan University, Taiwan
 
Prims Algorithm
Prims AlgorithmPrims Algorithm
Prims Algorithm
Sriram Raj
 
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
 
Minimum spanning tree
Minimum spanning treeMinimum spanning tree
Minimum spanning tree
Hinal Lunagariya
 
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
oneous
 
Mst(engl)
Mst(engl)Mst(engl)
Mst(engl)
yliu8698
 
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
 
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)
 
9 cm402.18
9 cm402.189 cm402.18
9 cm402.18
myrajendra
 
Minimum spanning tree
Minimum spanning treeMinimum spanning tree
Minimum spanning tree
Tanmay Baranwal
 
Prim algorithm
Prim algorithmPrim algorithm
Prim algorithm
University of Potsdam
 
Minimum Spanning Tree
Minimum Spanning TreeMinimum Spanning Tree
Minimum Spanning Tree
zhaokatherine
 
Prim's algorithm
Prim's algorithmPrim's algorithm
Prim's algorithm
Maher Alshammari
 
Spanning trees & applications
Spanning trees & applicationsSpanning trees & applications
Spanning trees & applications
Tech_MX
 
Cis cvs risc
Cis cvs riscCis cvs risc
Cis cvs risc
Maher Alshammari
 
Prims and kruskal algorithms
Prims and kruskal algorithmsPrims and kruskal algorithms
Prims and kruskal algorithms
Saga Valsalan
 

Viewers also liked (16)

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
 
Prims Algorithm
Prims AlgorithmPrims Algorithm
Prims Algorithm
 
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
 
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
 
Mst(engl)
Mst(engl)Mst(engl)
Mst(engl)
 
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
 
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)
 
9 cm402.18
9 cm402.189 cm402.18
9 cm402.18
 
Minimum spanning tree
Minimum spanning treeMinimum spanning tree
Minimum spanning tree
 
Prim algorithm
Prim algorithmPrim algorithm
Prim algorithm
 
Minimum Spanning Tree
Minimum Spanning TreeMinimum Spanning Tree
Minimum Spanning Tree
 
Prim's algorithm
Prim's algorithmPrim's algorithm
Prim's algorithm
 
Spanning trees & applications
Spanning trees & applicationsSpanning trees & applications
Spanning trees & applications
 
Cis cvs risc
Cis cvs riscCis cvs risc
Cis cvs risc
 
Prims and kruskal algorithms
Prims and kruskal algorithmsPrims and kruskal algorithms
Prims and kruskal algorithms
 

More from Hemant Gautam

Make a fool geekssay.com sharing
Make a fool geekssay.com sharingMake a fool geekssay.com sharing
Make a fool geekssay.com sharing
Hemant Gautam
 
1 men die-younger geekssay.com sharing
1 men die-younger geekssay.com sharing1 men die-younger geekssay.com sharing
1 men die-younger geekssay.com sharing
Hemant Gautam
 
Shopping cart project geekssay.com
Shopping cart project geekssay.comShopping cart project geekssay.com
Shopping cart project geekssay.com
Hemant Gautam
 
Segmentation geekssay.com
Segmentation  geekssay.comSegmentation  geekssay.com
Segmentation geekssay.com
Hemant Gautam
 
Atm traffic management geekssay.com
Atm traffic management  geekssay.comAtm traffic management  geekssay.com
Atm traffic management geekssay.com
Hemant Gautam
 
Disk scheduling geekssay.com
Disk scheduling geekssay.comDisk scheduling geekssay.com
Disk scheduling geekssay.com
Hemant Gautam
 
Knapsack Algorithm www.geekssay.com
Knapsack Algorithm www.geekssay.comKnapsack Algorithm www.geekssay.com
Knapsack Algorithm www.geekssay.com
Hemant Gautam
 
College Monitoring system BY: Geekssay.com
College Monitoring system BY: Geekssay.comCollege Monitoring system BY: Geekssay.com
College Monitoring system BY: Geekssay.com
Hemant Gautam
 

More from Hemant Gautam (8)

Make a fool geekssay.com sharing
Make a fool geekssay.com sharingMake a fool geekssay.com sharing
Make a fool geekssay.com sharing
 
1 men die-younger geekssay.com sharing
1 men die-younger geekssay.com sharing1 men die-younger geekssay.com sharing
1 men die-younger geekssay.com sharing
 
Shopping cart project geekssay.com
Shopping cart project geekssay.comShopping cart project geekssay.com
Shopping cart project geekssay.com
 
Segmentation geekssay.com
Segmentation  geekssay.comSegmentation  geekssay.com
Segmentation geekssay.com
 
Atm traffic management geekssay.com
Atm traffic management  geekssay.comAtm traffic management  geekssay.com
Atm traffic management geekssay.com
 
Disk scheduling geekssay.com
Disk scheduling geekssay.comDisk scheduling geekssay.com
Disk scheduling geekssay.com
 
Knapsack Algorithm www.geekssay.com
Knapsack Algorithm www.geekssay.comKnapsack Algorithm www.geekssay.com
Knapsack Algorithm www.geekssay.com
 
College Monitoring system BY: Geekssay.com
College Monitoring system BY: Geekssay.comCollege Monitoring system BY: Geekssay.com
College Monitoring system BY: Geekssay.com
 

Recently uploaded

The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
NgcHiNguyn25
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
Assessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptxAssessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptx
Kavitha Krishnan
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
Assessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptxAssessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptx
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 

Kruskals prims shared by: geekssay.com

  • 2. Minimum Connector Algorithms Kruskal’s algorithm Prim’s algorithm 1. Select the shortest edge in a 1. Select any vertex network 2. Select the shortest edge 2. Select the next shortest edge connected to that vertex which does not create a cycle 3. Select the shortest edge 3. Repeat step 2 until all vertices connected to any vertex have been connected already connected 4. Repeat step 3 until all vertices have been connected
  • 3. Example A cable company want to connect five villages to their network which currently extends to the market town of Avonford. What is the minimum length of cable needed? Brinleigh 5 Cornwell 3 4 8 6 8 Avonford Fingley Donster 7 5 4 2 Edan
  • 4. We model the situation as a network, then the problem is to find the minimum connector for the network B 5 C 3 4 8 6 8 A F D 7 5 4 2 E
  • 5. Kruskal’s Algorithm List the edges in order of size: B 5 C ED 2 AB 3 3 AE 4 4 8 6 CD 4 BC 5 8 EF 5 A D CF 6 7 F AF 7 5 BF 8 4 CF 8 2 E
  • 6. Kruskal’s Algorithm Select the shortest edge in the network B 5 C ED 2 3 4 8 6 8 A D 7 F 5 4 2 E
  • 7. Kruskal’s Algorithm Select the next shortest edge which does not B 5 create a cycle C ED 2 3 AB 3 4 8 6 8 A D 7 F 5 4 2 E
  • 8. Kruskal’s Algorithm Select the next shortest edge which does not B 5 create a cycle C ED 2 3 AB 3 4 8 6 CD 4 (or AE 4) 8 A D 7 F 5 4 2 E
  • 9. Kruskal’s Algorithm Select the next shortest edge which does not B 5 create a cycle C ED 2 3 AB 3 4 8 6 CD 4 AE 4 8 A D 7 F 5 4 2 E
  • 10. Kruskal’s Algorithm Select the next shortest edge which does not B 5 create a cycle C ED 2 3 AB 3 4 8 6 CD 4 AE 4 8 BC 5 – forms a cycle A D EF 5 7 F 5 4 2 E
  • 11. Kruskal’s Algorithm All vertices have been connected. B 5 C The solution is 3 ED 2 4 8 6 AB 3 CD 4 8 AE 4 A D EF 5 7 F 5 4 Total weight of tree: 18 2 E
  • 12. Prim’s Algorithm Select any vertex B 5 A C Select the shortest 3 edge connected to 4 8 6 that vertex 8 AB 3 A D 7 F 5 4 2 E
  • 13. Prim’s Algorithm Select the shortest edge connected to B 5 any vertex already C connected. 3 AE 4 4 8 6 8 A D 7 F 5 4 2 E
  • 14. Prim’s Algorithm Select the shortest edge connected to B 5 any vertex already C connected. 3 ED 2 4 8 6 8 A D 7 F 5 4 2 E
  • 15. Prim’s Algorithm Select the shortest edge connected to B 5 any vertex already C connected. 3 DC 4 4 8 6 8 A D 7 F 5 4 2 E
  • 16. Prim’s Algorithm Select the shortest edge connected to B 5 any vertex already C connected. 3 CB 5 – forms a cycle 4 8 6 EF 5 8 A D 7 F 5 4 2 E
  • 17. Prim’s Algorithm All vertices have been connected. B 5 C The solution is 3 ED 2 4 8 6 AB 3 CD 4 8 AE 4 A D EF 5 7 F 5 4 Total weight of tree: 18 2 E
  • 18. Some points to note •Both algorithms will always give solutions with the same length. •They will usually select edges in a different order – you must show this in your workings. •Occasionally they will use different edges – this may happen when you have to choose between edges with the same length. In this case there is more than one minimum connector for the network.