SlideShare ist ein Scribd-Unternehmen logo
1 von 18
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.

Weitere ähnliche Inhalte

Was ist angesagt?

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 structureEMEY GUJJAR
 
Radix sort concept
Radix sort conceptRadix sort concept
Radix sort conceptZeeshan Ali
 
[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
 
Single sourceshortestpath by emad
Single sourceshortestpath by emadSingle sourceshortestpath by emad
Single sourceshortestpath by emadKazi Emad
 
Incremental Graph Queries for Cypher
Incremental Graph Queries for CypherIncremental Graph Queries for Cypher
Incremental Graph Queries for CypheropenCypher
 
Unit 5 graphs minimum spanning trees
Unit 5   graphs minimum spanning treesUnit 5   graphs minimum spanning trees
Unit 5 graphs minimum spanning treeskalyanineve
 
Range Minimum Queries
Range Minimum QueriesRange Minimum Queries
Range Minimum QueriesBenjamin Sach
 
Bellman ford algorithm
Bellman ford algorithmBellman ford algorithm
Bellman ford algorithmA. S. M. Shafi
 
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 TechniqueLeonides 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 rootsNorthside ISD
 
Lecture 16 data structures and algorithms
Lecture 16 data structures and algorithmsLecture 16 data structures and algorithms
Lecture 16 data structures and algorithmsAakash deep Singhal
 

Was ist angesagt? (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
 

Andere mochten auch

Prims Algorithm
Prims AlgorithmPrims Algorithm
Prims AlgorithmSriram 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
 
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
 
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)
 
Minimum Spanning Tree
Minimum Spanning TreeMinimum Spanning Tree
Minimum Spanning Treezhaokatherine
 
Spanning trees & applications
Spanning trees & applicationsSpanning trees & applications
Spanning trees & applicationsTech_MX
 
Prims and kruskal algorithms
Prims and kruskal algorithmsPrims and kruskal algorithms
Prims and kruskal algorithmsSaga Valsalan
 

Andere mochten auch (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
 

Mehr von Hemant Gautam

Make a fool geekssay.com sharing
Make a fool geekssay.com sharingMake a fool geekssay.com sharing
Make a fool geekssay.com sharingHemant 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 sharingHemant Gautam
 
Shopping cart project geekssay.com
Shopping cart project geekssay.comShopping cart project geekssay.com
Shopping cart project geekssay.comHemant Gautam
 
Segmentation geekssay.com
Segmentation  geekssay.comSegmentation  geekssay.com
Segmentation geekssay.comHemant Gautam
 
Atm traffic management geekssay.com
Atm traffic management  geekssay.comAtm traffic management  geekssay.com
Atm traffic management geekssay.comHemant Gautam
 
Disk scheduling geekssay.com
Disk scheduling geekssay.comDisk scheduling geekssay.com
Disk scheduling geekssay.comHemant Gautam
 
Knapsack Algorithm www.geekssay.com
Knapsack Algorithm www.geekssay.comKnapsack Algorithm www.geekssay.com
Knapsack Algorithm www.geekssay.comHemant Gautam
 
College Monitoring system BY: Geekssay.com
College Monitoring system BY: Geekssay.comCollege Monitoring system BY: Geekssay.com
College Monitoring system BY: Geekssay.comHemant Gautam
 

Mehr von 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
 

Kürzlich hochgeladen

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
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
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterMateoGardella
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
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
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfChris Hunter
 
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
 
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
 
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
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
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
 

Kürzlich hochgeladen (20)

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
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
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
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
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
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
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
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
 
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
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
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...
 

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.