SlideShare a Scribd company logo
1 of 40
Application of greedy method:
Prim’s Algorithm
Greedy Method ???
A greedy method is an method that follows
the problem solving technique of making the
locally optimal choice at each stage with the
hope of finding a global optimum.
Prim’s Algorithm
Prim's algorithm is a greedy algorithm that
finds a minimum spanning tree for
a connected weighted undirected graph. This
means it finds a subset of the edges that forms
a tree that includes every vertex, where the
total weight of all the edges in the tree is
minimized.
Spanning Tree ???
A spanning tree of a connected graph G can
be defined as a maximal set of edges of G that
contains no cycle, or as a minimal set of edges
that connect all vertices.
Minimum Spanning Tree ???
A minimum spanning tree is a subgraph of an
undirected weighted graph G, such that

• it is a tree (i.e., it is acyclic)
• it covers all the vertices V
    – contains |V| - 1 edges
• the total cost associated with tree edges is the
  minimum among all possible spanning trees
• not necessarily unique
Algorithm
Example 1
5
        A               B
    4       6       2

        2       D           3
C

    3       1       2
        E               F
                4
5
        A               B
    4       6       2

        2       D           3
C

    3       1       2
        E               F
                4
5
        A               B
    4       6       2

        2       D           3
C

    3       1       2
        E               F
                4
5
        A               B
    4       6       2

        2       D           3
C

    3       1       2
        E               F
                4
A               B
                    2

        2       D           3
C

    3       1       2
        E               F
                4
A               B
                    2

        2       D           3
C

    3       1       2
        E               F
A               B
                    2

        2       D           3
C

    3       1       2
        E               F
A               B
                    2

        2       D
C

    3       1       2
        E               F
A               B
                    2

        2       D
C

    3       1       2
        E               F
minimum- spanning tree


                A                    B
                                 2

               2             D
C

        3                1       2
                E                    F
Example 2
Prim’s Algorithm
                    9           b
    a       2           6
                d
                        4       5
    5       4

                    5       e
        c
Prim’s algorithm


                    9           b
    a       2           6
                d
                        4       5
    5       4

                    5       e
        c


    The MST initially consists of the vertex e
Prim’s algorithm


                    9           b
    a       2           6
                d
                        4       5
    5       4

                    5       e
        c
Prim’s algorithm


                    9           b
    a       2           6
                d
                        4       5
    5       4

                    5       e
        c
Prim’s algorithm


                    9           b
    a       2           6
                d
                        4       5
    5       4

                    5       e
        c
Prim’s algorithm


                    9           b
    a       2           6
                d
                        4       5
    5       4

                    5       e
        c

        The final minimum spanning tree
Example 3
Weight (T) = 23 + 29 + 31 + 32 + 47 + 54 + 66 = 282
Problem: Laying Telephone
Wire




             Central office
Wiring: Normal Approach




              Central office




           Expensive!
Wiring: Better Approach




                           Central office




Minimize the total length of wire connecting the customers
Thank You

More Related Content

What's hot

Dinive conquer algorithm
Dinive conquer algorithmDinive conquer algorithm
Dinive conquer algorithm
Mohd Arif
 
Time and space complexity
Time and space complexityTime and space complexity
Time and space complexity
Ankit Katiyar
 

What's hot (20)

Prims and kruskal algorithms
Prims and kruskal algorithmsPrims and kruskal algorithms
Prims and kruskal algorithms
 
Ch04
Ch04Ch04
Ch04
 
Kruskal & Prim's Algorithm
Kruskal & Prim's AlgorithmKruskal & Prim's Algorithm
Kruskal & Prim's Algorithm
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
 
Kruskal Algorithm
Kruskal AlgorithmKruskal Algorithm
Kruskal Algorithm
 
Dinive conquer algorithm
Dinive conquer algorithmDinive conquer algorithm
Dinive conquer algorithm
 
Ch 2 lattice & boolean algebra
Ch 2 lattice & boolean algebraCh 2 lattice & boolean algebra
Ch 2 lattice & boolean algebra
 
Knapsack
KnapsackKnapsack
Knapsack
 
Presentation of daa on approximation algorithm and vertex cover problem
Presentation of daa on approximation algorithm and vertex cover problem Presentation of daa on approximation algorithm and vertex cover problem
Presentation of daa on approximation algorithm and vertex cover problem
 
Graph theory - Traveling Salesman and Chinese Postman
Graph theory - Traveling Salesman and Chinese PostmanGraph theory - Traveling Salesman and Chinese Postman
Graph theory - Traveling Salesman and Chinese Postman
 
Solution of N Queens Problem genetic algorithm
Solution of N Queens Problem genetic algorithm  Solution of N Queens Problem genetic algorithm
Solution of N Queens Problem genetic algorithm
 
Knowledge representation
Knowledge representationKnowledge representation
Knowledge representation
 
Kruskal’s algorithm
Kruskal’s algorithmKruskal’s algorithm
Kruskal’s algorithm
 
Branch and bounding : Data structures
Branch and bounding : Data structuresBranch and bounding : Data structures
Branch and bounding : Data structures
 
Unit 1 chapter 1 Design and Analysis of Algorithms
Unit 1   chapter 1 Design and Analysis of AlgorithmsUnit 1   chapter 1 Design and Analysis of Algorithms
Unit 1 chapter 1 Design and Analysis of Algorithms
 
data structures- back tracking
data structures- back trackingdata structures- back tracking
data structures- back tracking
 
5.3 dynamic programming
5.3 dynamic programming5.3 dynamic programming
5.3 dynamic programming
 
Number theory lecture (part 1)
Number theory lecture (part 1)Number theory lecture (part 1)
Number theory lecture (part 1)
 
Problemas de aplicação pa e pg
Problemas de aplicação pa e pgProblemas de aplicação pa e pg
Problemas de aplicação pa e pg
 
Time and space complexity
Time and space complexityTime and space complexity
Time and space complexity
 

Viewers also liked

Application of greedy method
Application  of  greedy methodApplication  of  greedy method
Application of greedy method
Tech_MX
 
Spanning trees & applications
Spanning trees & applicationsSpanning trees & applications
Spanning trees & applications
Tech_MX
 
モリンガライフパウダーの軌跡
モリンガライフパウダーの軌跡モリンガライフパウダーの軌跡
モリンガライフパウダーの軌跡
Tadahisa Kumagai
 
Io processing
Io processingIo processing
Io processing
Tech_MX
 

Viewers also liked (20)

Application of greedy method
Application  of  greedy methodApplication  of  greedy method
Application of greedy method
 
Spanning trees & applications
Spanning trees & applicationsSpanning trees & applications
Spanning trees & applications
 
Greedy Algorithms
Greedy AlgorithmsGreedy Algorithms
Greedy Algorithms
 
Greedymethod
GreedymethodGreedymethod
Greedymethod
 
Kruskal Algorithm
Kruskal AlgorithmKruskal Algorithm
Kruskal Algorithm
 
Greedy Algorithm
Greedy AlgorithmGreedy Algorithm
Greedy Algorithm
 
Greedy
GreedyGreedy
Greedy
 
Greedy Algorihm
Greedy AlgorihmGreedy Algorihm
Greedy Algorihm
 
Greedy algorithm
Greedy algorithmGreedy algorithm
Greedy algorithm
 
モリンガライフパウダーの軌跡
モリンガライフパウダーの軌跡モリンガライフパウダーの軌跡
モリンガライフパウダーの軌跡
 
Presentation1
Presentation1Presentation1
Presentation1
 
Special techniques
Special techniquesSpecial techniques
Special techniques
 
モリンガ+(プラス)レシピ集
モリンガ+(プラス)レシピ集モリンガ+(プラス)レシピ集
モリンガ+(プラス)レシピ集
 
モリンガライフパウダーの軌跡
モリンガライフパウダーの軌跡モリンガライフパウダーの軌跡
モリンガライフパウダーの軌跡
 
Physical examination of cattle lecture
Physical examination of cattle lecture Physical examination of cattle lecture
Physical examination of cattle lecture
 
Back to School Night 2012 2013
Back to School Night 2012 2013Back to School Night 2012 2013
Back to School Night 2012 2013
 
Io processing
Io processingIo processing
Io processing
 
Branch and bound
Branch and boundBranch and bound
Branch and bound
 
モリンガとは?
モリンガとは?モリンガとは?
モリンガとは?
 
Knapsack Algorithm www.geekssay.com
Knapsack Algorithm www.geekssay.comKnapsack Algorithm www.geekssay.com
Knapsack Algorithm www.geekssay.com
 

Similar to Application of greedy method prim (20)

Day 2 adding polynomials senteo
Day 2 adding polynomials senteoDay 2 adding polynomials senteo
Day 2 adding polynomials senteo
 
Kruskals prims shared by: geekssay.com
Kruskals prims shared by: geekssay.comKruskals prims shared by: geekssay.com
Kruskals prims shared by: geekssay.com
 
Double patterning (4/20 update)
Double patterning (4/20 update)Double patterning (4/20 update)
Double patterning (4/20 update)
 
Chapter two(was 1) v9-oldformat-c
Chapter two(was 1) v9-oldformat-cChapter two(was 1) v9-oldformat-c
Chapter two(was 1) v9-oldformat-c
 
Chapter two(was 1) v9-oldformat
Chapter two(was 1) v9-oldformatChapter two(was 1) v9-oldformat
Chapter two(was 1) v9-oldformat
 
Geom4-4
Geom4-4Geom4-4
Geom4-4
 
09 trial kedah_s1
09 trial kedah_s109 trial kedah_s1
09 trial kedah_s1
 
Chapter two(was 1) v9-oldformat
Chapter two(was 1) v9-oldformatChapter two(was 1) v9-oldformat
Chapter two(was 1) v9-oldformat
 
Chapter two(was 1) v9-oldformat-cd-b
Chapter two(was 1) v9-oldformat-cd-bChapter two(was 1) v9-oldformat-cd-b
Chapter two(was 1) v9-oldformat-cd-b
 
Dicionário de acordes para teclado
Dicionário de acordes para tecladoDicionário de acordes para teclado
Dicionário de acordes para teclado
 
Saes tables
Saes tablesSaes tables
Saes tables
 
Day 12 factoring trinomials senteo
Day 12 factoring trinomials senteoDay 12 factoring trinomials senteo
Day 12 factoring trinomials senteo
 
Module 5 Indices PMR
Module 5 Indices PMRModule 5 Indices PMR
Module 5 Indices PMR
 
Datamining 8th hclustering
Datamining 8th hclusteringDatamining 8th hclustering
Datamining 8th hclustering
 
Datamining 8th Hclustering
Datamining 8th HclusteringDatamining 8th Hclustering
Datamining 8th Hclustering
 
Gabarito vestibular
Gabarito vestibularGabarito vestibular
Gabarito vestibular
 
1.2.4
1.2.41.2.4
1.2.4
 
Worked examples projects unit 1
Worked examples projects unit 1Worked examples projects unit 1
Worked examples projects unit 1
 
Mst(engl)
Mst(engl)Mst(engl)
Mst(engl)
 
Chapter two(was 1) v9-oldformat
Chapter two(was 1) v9-oldformatChapter two(was 1) v9-oldformat
Chapter two(was 1) v9-oldformat
 

More from Tech_MX

Virtual base class
Virtual base classVirtual base class
Virtual base class
Tech_MX
 
Theory of estimation
Theory of estimationTheory of estimation
Theory of estimation
Tech_MX
 
Templates in C++
Templates in C++Templates in C++
Templates in C++
Tech_MX
 
String & its application
String & its applicationString & its application
String & its application
Tech_MX
 
Statistical quality__control_2
Statistical  quality__control_2Statistical  quality__control_2
Statistical quality__control_2
Tech_MX
 
Stack data structure
Stack data structureStack data structure
Stack data structure
Tech_MX
 
Stack Data Structure & It's Application
Stack Data Structure & It's Application Stack Data Structure & It's Application
Stack Data Structure & It's Application
Tech_MX
 
Set data structure 2
Set data structure 2Set data structure 2
Set data structure 2
Tech_MX
 
Set data structure
Set data structure Set data structure
Set data structure
Tech_MX
 
Real time Operating System
Real time Operating SystemReal time Operating System
Real time Operating System
Tech_MX
 
Mouse interrupts (Assembly Language & C)
Mouse interrupts (Assembly Language & C)Mouse interrupts (Assembly Language & C)
Mouse interrupts (Assembly Language & C)
Tech_MX
 
Motherboard of a pc
Motherboard of a pcMotherboard of a pc
Motherboard of a pc
Tech_MX
 
More on Lex
More on LexMore on Lex
More on Lex
Tech_MX
 
MultiMedia dbms
MultiMedia dbmsMultiMedia dbms
MultiMedia dbms
Tech_MX
 
Merging files (Data Structure)
Merging files (Data Structure)Merging files (Data Structure)
Merging files (Data Structure)
Tech_MX
 
Memory dbms
Memory dbmsMemory dbms
Memory dbms
Tech_MX
 

More from Tech_MX (20)

Virtual base class
Virtual base classVirtual base class
Virtual base class
 
Uid
UidUid
Uid
 
Theory of estimation
Theory of estimationTheory of estimation
Theory of estimation
 
Templates in C++
Templates in C++Templates in C++
Templates in C++
 
String & its application
String & its applicationString & its application
String & its application
 
Statistical quality__control_2
Statistical  quality__control_2Statistical  quality__control_2
Statistical quality__control_2
 
Stack data structure
Stack data structureStack data structure
Stack data structure
 
Stack Data Structure & It's Application
Stack Data Structure & It's Application Stack Data Structure & It's Application
Stack Data Structure & It's Application
 
Spss
SpssSpss
Spss
 
Set data structure 2
Set data structure 2Set data structure 2
Set data structure 2
 
Set data structure
Set data structure Set data structure
Set data structure
 
Real time Operating System
Real time Operating SystemReal time Operating System
Real time Operating System
 
Parsing
ParsingParsing
Parsing
 
Mouse interrupts (Assembly Language & C)
Mouse interrupts (Assembly Language & C)Mouse interrupts (Assembly Language & C)
Mouse interrupts (Assembly Language & C)
 
Motherboard of a pc
Motherboard of a pcMotherboard of a pc
Motherboard of a pc
 
More on Lex
More on LexMore on Lex
More on Lex
 
MultiMedia dbms
MultiMedia dbmsMultiMedia dbms
MultiMedia dbms
 
Merging files (Data Structure)
Merging files (Data Structure)Merging files (Data Structure)
Merging files (Data Structure)
 
Memory dbms
Memory dbmsMemory dbms
Memory dbms
 
Linkers
LinkersLinkers
Linkers
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 

Application of greedy method prim

  • 1. Application of greedy method: Prim’s Algorithm
  • 2. Greedy Method ??? A greedy method is an method that follows the problem solving technique of making the locally optimal choice at each stage with the hope of finding a global optimum.
  • 3. Prim’s Algorithm Prim's algorithm is a greedy algorithm that finds a minimum spanning tree for a connected weighted undirected graph. This means it finds a subset of the edges that forms a tree that includes every vertex, where the total weight of all the edges in the tree is minimized.
  • 4. Spanning Tree ??? A spanning tree of a connected graph G can be defined as a maximal set of edges of G that contains no cycle, or as a minimal set of edges that connect all vertices.
  • 5.
  • 6. Minimum Spanning Tree ??? A minimum spanning tree is a subgraph of an undirected weighted graph G, such that • it is a tree (i.e., it is acyclic) • it covers all the vertices V – contains |V| - 1 edges • the total cost associated with tree edges is the minimum among all possible spanning trees • not necessarily unique
  • 7.
  • 9.
  • 10.
  • 12. 5 A B 4 6 2 2 D 3 C 3 1 2 E F 4
  • 13. 5 A B 4 6 2 2 D 3 C 3 1 2 E F 4
  • 14. 5 A B 4 6 2 2 D 3 C 3 1 2 E F 4
  • 15. 5 A B 4 6 2 2 D 3 C 3 1 2 E F 4
  • 16. A B 2 2 D 3 C 3 1 2 E F 4
  • 17. A B 2 2 D 3 C 3 1 2 E F
  • 18. A B 2 2 D 3 C 3 1 2 E F
  • 19. A B 2 2 D C 3 1 2 E F
  • 20. A B 2 2 D C 3 1 2 E F
  • 21. minimum- spanning tree A B 2 2 D C 3 1 2 E F
  • 23. Prim’s Algorithm 9 b a 2 6 d 4 5 5 4 5 e c
  • 24. Prim’s algorithm 9 b a 2 6 d 4 5 5 4 5 e c The MST initially consists of the vertex e
  • 25. Prim’s algorithm 9 b a 2 6 d 4 5 5 4 5 e c
  • 26. Prim’s algorithm 9 b a 2 6 d 4 5 5 4 5 e c
  • 27. Prim’s algorithm 9 b a 2 6 d 4 5 5 4 5 e c
  • 28. Prim’s algorithm 9 b a 2 6 d 4 5 5 4 5 e c The final minimum spanning tree
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36. Weight (T) = 23 + 29 + 31 + 32 + 47 + 54 + 66 = 282
  • 38. Wiring: Normal Approach Central office Expensive!
  • 39. Wiring: Better Approach Central office Minimize the total length of wire connecting the customers