SlideShare a Scribd company logo
APPLICATION OF GREEDY METHOD

KRUSKAL’S ALGORITHM TO FIND
MINIMUM
        COST SPANNING TREES
   An algorithm is a mathematical procedure often used to
    solve optimization problems in a finite number of steps.

   Most solution algorithms make choices based on a
    global overview of all current and future possibilities
    aiming at reaching the single global optimum solution.

   Greedy algorithms make choices that look best at that
    every moment.
   When compared to algorithms that guarantee to yield a
    global optimum solution, greedy algorithms have
    several advantages:

   They are easier to implement, they require much less
    computing resources, they are much faster to execute.

   Their only disadvantage being that they do not always
    reach the global optimum solution
    when the global optimum solution is not
    reached, most of the times the reached sub- optimal
    solution is a very good solution.

   Several classical optimization problems like minimum
    spanning tree and optimal prefix codes for data
    compression yield global optimum solutions using
    greedy algorithm.
   A tree T is said to be a spanning tree of a connected
    graph G if T is a subgraph of G and T contains all vertices
    of G.
   Since the vertices of G are barely hanging together in a
    spanning tree, it is a sort of skeleton of the original
    graph g. so, a spanning tree is called a skeleton or
    scaffolding of G.
   Among the spanning trees of G, one with the smallest
    weight is called minimal spanning tree or shortest
    spanning tree or shortest-distance spanning tree.
A second greedy algorithm was developed by Joseph Kruskal.

Steps in Kruskal’s algorithm:
 list all edges of G in order of increasing weight.
 Select a smallest edge of G.
 For each successive step, select (from all remaining
  edges of G) another smallest edge that makes no circuit
 with the previously selected edges.
 Continue until n-1 edges have been selected.
      At each stage, the algorithm chooses an edge
     to add to its current partial solution. To do so, it needs
    to test each candidate edge (u ,v ) to
    see whether the endpoints u and v lie in different
    components; otherwise the edge produces a
    cycle.
5
              A                               B
    4                         6           2

            2                     D               3
C

    3                         1           2
              E                               F
                                      4
        Kruskal's Algorithm
enqueue edges of G in a queue in increasing order of
cost.
T=;
while(queue is not empty)
{
       dequeue an edge e;
       if(e does not create a cycle with edges in T)
       add e to T;
}
return T;
5
              A                               B
    4                         6           2

            2                     D               3
C

    3                         1           2
              E                               F
                                      4
        Kruskal's Algorithm
5
              A                               B
    4                         6           2

            2                     D               3
C

    3                         1           2
              E                               F
                                      4
        Kruskal's Algorithm
5
              A                               B
    4                         6           2

            2                     D               3
C

    3                         1           2
              E                               F
                                      4
        Kruskal's Algorithm
5
              A                               B
    4                         6           2

            2                     D               3
C

    3                         1           2
              E                               F
                                      4
        Kruskal's Algorithm
5
              A                               B
    4                         6           2

            2                     D               3   cycle!!
C

    3                         1           2
              E                               F
                                      4
        Kruskal's Algorithm
5
              A                               B
    4                         6           2

            2                     D               3
C

    3                         1           2
              E                               F
                                      4
        Kruskal's Algorithm
5
              A                               B
    4                         6           2

            2                     D               3
C

    3                         1           2
              E                               F
                                      4
        Kruskal's Algorithm
minimum- spanning tree



                    A                           B
                                            2

                  2                     D
C

        3                           1       2
                    E                           F

              Kruskal's Algorithm
8                   7

             b                   c           d        9
    4

                             2
        11                                       14        e
a                    i               4
                 7           6
                                                      10
    8
             h                   g           f
                         1               2
8                   7
             b                   c               d         9
    4
                             2
a       11                                           14        e
                         i           4
                 7           6
                                                          10
    8
             h                   g               f
                         1                   2




                     8                   7
             b                   c               d        9
    4
                             2
a       11                                           14        e
                     i               4
                 7           6
                                                          10
    8
             h                   g               f
                     1                   2

                                                                   19
8               7
             b               c           d        9
    4
                         2
a       11                                   14        e
                     i           4
                 7       6
                                                  10
    8
             h               g           f
                     1               2



                     8               7
             b               c           d        9
    4
                         2
a       11                                   14        e
                     i           4
                 7       6
                                                  10
    8
             h               g           f
                     1               2

                                                           20
8               7
             b               c           d        9
    4
                         2
a       11                                   14        e
                     i           4
                 7       6
                                                  10
    8
             h               g           f
                     1               2


                     8               7
             b               c           d        9
    4
                         2
a       11                                   14        e
                     i           4
                 7       6
                                                  10
    8
             h               g           f
                     1               2


                                                           21
8               7
             b               c           d        9
    4
                         2
a       11                                   14        e
                     i           4
                 7       6
                                                  10
    8
             h               g           f
                     1               2



                     8               7
             b               c           d        9
    4
                         2
a       11                                   14        e
                     i           4
                 7       6
                                                  10
    8
             h               g           f
                     1               2


                                                           22
8               7
                     b               c           d        9
            4
                                 2
        a       11                                   14        e
                             i           4
                         7       6
                                                          10
            8
                     h               g           f
                             1               2

MINIMAL SPANNING TREEE
                             8               7
                     b               c           d        9
            4
                                 2
        a       11                                   14        e
                             i           4
                         7       6
                                                          10
            8
                     h               g           f
                             1               2


                                                                   23
   Initialization O(V) time
   Sorting the edges Q(E lg E) = Q(E lg V) (why?)
   O(E) calls to FindSet
   Union costs
     Let t(v) – the number of times v is moved to a new
      cluster
     Each time a vertex is moved to a new cluster the size
      of the cluster containing the vertex at least doubles:
      t(v) log V
     Total time spent doing Union vV
                                       t (v)  V log V
   Total time: O(E lg V)
                                                               24
   Where ever the minimum distance is needed to achieve
    there this algorithm gets place.
   For example.
     In telephone lining under the ground, they have to connect all
      the cities with the minimum amount of wire.
     If the new connection is in position to add between cities, there
      we have to consider the minimum cost distance.
     Assume, if the minimum distance is not calculated, the wastage
      of wires will be in peak.
   Railways track construction.
   National highway construction.
   Flyover bridge construction.
   Network between two intranets.
   The another non-technical example will be as,
     The by-pass rider or point to point buses will move on with the
      minimum distance path to reach the destination much faster.
      They will never circulate their bus through unwanted towns and
      villages.

More Related Content

What's hot (20)

PPTX
Knapsack problem using greedy approach
padmeshagrekar
 
PDF
introduction to graph theory
Chuckie Balbuena
 
PPT
Floyd Warshall Algorithm
InteX Research Lab
 
PPT
Minimum spanning tree
Hinal Lunagariya
 
PPTX
Graph Theory
Ehsan Hamzei
 
PPTX
Dijkstra’S Algorithm
ami_01
 
PPTX
Single source Shortest path algorithm with example
VINITACHAUHAN21
 
PDF
linear classification
nep_test_account
 
PPTX
Sum of subset problem.pptx
V.V.Vanniaperumal College for Women
 
PPTX
Task programming
Yogendra Tamang
 
PPTX
General Quadrature Equation
MrinalDev1
 
PPTX
Breadth First Search & Depth First Search
Kevin Jadiya
 
PPTX
3D transformation in computer graphics
SHIVANI SONI
 
PPT
Divide and conquer
Dr Shashikant Athawale
 
PPT
ADA - Minimum Spanning Tree Prim Kruskal and Dijkstra
Sahil Kumar
 
PPTX
Kruskal’s algorithm
Abdul Moiz Lakhani
 
PPTX
Bootstrapping in Compiler
Akhil Kaushik
 
PPTX
Unit v
TPLatchoumi
 
PPTX
Water jug problem ai part 6
Kirti Verma
 
PDF
Graph theory and its applications
Manikanta satyala
 
Knapsack problem using greedy approach
padmeshagrekar
 
introduction to graph theory
Chuckie Balbuena
 
Floyd Warshall Algorithm
InteX Research Lab
 
Minimum spanning tree
Hinal Lunagariya
 
Graph Theory
Ehsan Hamzei
 
Dijkstra’S Algorithm
ami_01
 
Single source Shortest path algorithm with example
VINITACHAUHAN21
 
linear classification
nep_test_account
 
Sum of subset problem.pptx
V.V.Vanniaperumal College for Women
 
Task programming
Yogendra Tamang
 
General Quadrature Equation
MrinalDev1
 
Breadth First Search & Depth First Search
Kevin Jadiya
 
3D transformation in computer graphics
SHIVANI SONI
 
Divide and conquer
Dr Shashikant Athawale
 
ADA - Minimum Spanning Tree Prim Kruskal and Dijkstra
Sahil Kumar
 
Kruskal’s algorithm
Abdul Moiz Lakhani
 
Bootstrapping in Compiler
Akhil Kaushik
 
Unit v
TPLatchoumi
 
Water jug problem ai part 6
Kirti Verma
 
Graph theory and its applications
Manikanta satyala
 

More from Tech_MX (20)

PPTX
Virtual base class
Tech_MX
 
PPTX
Uid
Tech_MX
 
PPTX
Theory of estimation
Tech_MX
 
PPTX
Templates in C++
Tech_MX
 
PPT
String & its application
Tech_MX
 
PPTX
Statistical quality__control_2
Tech_MX
 
PPTX
Stack data structure
Tech_MX
 
PPT
Stack Data Structure & It's Application
Tech_MX
 
PPTX
Spss
Tech_MX
 
PPTX
Spanning trees & applications
Tech_MX
 
PPTX
Set data structure 2
Tech_MX
 
PPTX
Set data structure
Tech_MX
 
PPTX
Real time Operating System
Tech_MX
 
PPTX
Parsing
Tech_MX
 
PPTX
Mouse interrupts (Assembly Language & C)
Tech_MX
 
PPT
Motherboard of a pc
Tech_MX
 
PPTX
More on Lex
Tech_MX
 
PPTX
MultiMedia dbms
Tech_MX
 
PPTX
Merging files (Data Structure)
Tech_MX
 
PPTX
Memory dbms
Tech_MX
 
Virtual base class
Tech_MX
 
Uid
Tech_MX
 
Theory of estimation
Tech_MX
 
Templates in C++
Tech_MX
 
String & its application
Tech_MX
 
Statistical quality__control_2
Tech_MX
 
Stack data structure
Tech_MX
 
Stack Data Structure & It's Application
Tech_MX
 
Spss
Tech_MX
 
Spanning trees & applications
Tech_MX
 
Set data structure 2
Tech_MX
 
Set data structure
Tech_MX
 
Real time Operating System
Tech_MX
 
Parsing
Tech_MX
 
Mouse interrupts (Assembly Language & C)
Tech_MX
 
Motherboard of a pc
Tech_MX
 
More on Lex
Tech_MX
 
MultiMedia dbms
Tech_MX
 
Merging files (Data Structure)
Tech_MX
 
Memory dbms
Tech_MX
 
Ad

Recently uploaded (20)

PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
PPTX
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
 
PPTX
Practical Applications of AI in Local Government
OnBoard
 
PDF
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
 
PDF
Supporting the NextGen 911 Digital Transformation with FME
Safe Software
 
PPTX
2025 HackRedCon Cyber Career Paths.pptx Scott Stanton
Scott Stanton
 
PDF
Proactive Server and System Monitoring with FME: Using HTTP and System Caller...
Safe Software
 
PPTX
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Pitch ...
Michele Kryston
 
PPTX
Wondershare Filmora Crack Free Download 2025
josanj305
 
PDF
''Taming Explosive Growth: Building Resilience in a Hyper-Scaled Financial Pl...
Fwdays
 
PDF
Java 25 and Beyond - A Roadmap of Innovations
Ana-Maria Mihalceanu
 
PDF
DoS Attack vs DDoS Attack_ The Silent Wars of the Internet.pdf
CyberPro Magazine
 
PDF
Pipeline Industry IoT - Real Time Data Monitoring
Safe Software
 
PDF
“A Re-imagination of Embedded Vision System Design,” a Presentation from Imag...
Edge AI and Vision Alliance
 
PDF
My Journey from CAD to BIM: A True Underdog Story
Safe Software
 
PDF
Why aren't you using FME Flow's CPU Time?
Safe Software
 
PPTX
CapCut Pro PC Crack Latest Version Free Free
josanj305
 
PPTX
01_Approach Cyber- DORA Incident Management.pptx
FinTech Belgium
 
PDF
“Scaling i.MX Applications Processors’ Native Edge AI with Discrete AI Accele...
Edge AI and Vision Alliance
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
 
Practical Applications of AI in Local Government
OnBoard
 
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
 
Supporting the NextGen 911 Digital Transformation with FME
Safe Software
 
2025 HackRedCon Cyber Career Paths.pptx Scott Stanton
Scott Stanton
 
Proactive Server and System Monitoring with FME: Using HTTP and System Caller...
Safe Software
 
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Pitch ...
Michele Kryston
 
Wondershare Filmora Crack Free Download 2025
josanj305
 
''Taming Explosive Growth: Building Resilience in a Hyper-Scaled Financial Pl...
Fwdays
 
Java 25 and Beyond - A Roadmap of Innovations
Ana-Maria Mihalceanu
 
DoS Attack vs DDoS Attack_ The Silent Wars of the Internet.pdf
CyberPro Magazine
 
Pipeline Industry IoT - Real Time Data Monitoring
Safe Software
 
“A Re-imagination of Embedded Vision System Design,” a Presentation from Imag...
Edge AI and Vision Alliance
 
My Journey from CAD to BIM: A True Underdog Story
Safe Software
 
Why aren't you using FME Flow's CPU Time?
Safe Software
 
CapCut Pro PC Crack Latest Version Free Free
josanj305
 
01_Approach Cyber- DORA Incident Management.pptx
FinTech Belgium
 
“Scaling i.MX Applications Processors’ Native Edge AI with Discrete AI Accele...
Edge AI and Vision Alliance
 
Ad

Application of greedy method

  • 1. APPLICATION OF GREEDY METHOD KRUSKAL’S ALGORITHM TO FIND MINIMUM COST SPANNING TREES
  • 2. An algorithm is a mathematical procedure often used to solve optimization problems in a finite number of steps.  Most solution algorithms make choices based on a global overview of all current and future possibilities aiming at reaching the single global optimum solution.  Greedy algorithms make choices that look best at that every moment.
  • 3. When compared to algorithms that guarantee to yield a global optimum solution, greedy algorithms have several advantages:  They are easier to implement, they require much less computing resources, they are much faster to execute.  Their only disadvantage being that they do not always reach the global optimum solution
  • 4. when the global optimum solution is not reached, most of the times the reached sub- optimal solution is a very good solution.  Several classical optimization problems like minimum spanning tree and optimal prefix codes for data compression yield global optimum solutions using greedy algorithm.
  • 5. A tree T is said to be a spanning tree of a connected graph G if T is a subgraph of G and T contains all vertices of G.  Since the vertices of G are barely hanging together in a spanning tree, it is a sort of skeleton of the original graph g. so, a spanning tree is called a skeleton or scaffolding of G.  Among the spanning trees of G, one with the smallest weight is called minimal spanning tree or shortest spanning tree or shortest-distance spanning tree.
  • 6. A second greedy algorithm was developed by Joseph Kruskal. Steps in Kruskal’s algorithm:  list all edges of G in order of increasing weight.  Select a smallest edge of G.  For each successive step, select (from all remaining edges of G) another smallest edge that makes no circuit  with the previously selected edges.  Continue until n-1 edges have been selected.
  • 7. At each stage, the algorithm chooses an edge to add to its current partial solution. To do so, it needs to test each candidate edge (u ,v ) to see whether the endpoints u and v lie in different components; otherwise the edge produces a cycle.
  • 8. 5 A B 4 6 2 2 D 3 C 3 1 2 E F 4 Kruskal's Algorithm
  • 9. enqueue edges of G in a queue in increasing order of cost. T=; while(queue is not empty) { dequeue an edge e; if(e does not create a cycle with edges in T) add e to T; } return T;
  • 10. 5 A B 4 6 2 2 D 3 C 3 1 2 E F 4 Kruskal's Algorithm
  • 11. 5 A B 4 6 2 2 D 3 C 3 1 2 E F 4 Kruskal's Algorithm
  • 12. 5 A B 4 6 2 2 D 3 C 3 1 2 E F 4 Kruskal's Algorithm
  • 13. 5 A B 4 6 2 2 D 3 C 3 1 2 E F 4 Kruskal's Algorithm
  • 14. 5 A B 4 6 2 2 D 3 cycle!! C 3 1 2 E F 4 Kruskal's Algorithm
  • 15. 5 A B 4 6 2 2 D 3 C 3 1 2 E F 4 Kruskal's Algorithm
  • 16. 5 A B 4 6 2 2 D 3 C 3 1 2 E F 4 Kruskal's Algorithm
  • 17. minimum- spanning tree A B 2 2 D C 3 1 2 E F Kruskal's Algorithm
  • 18. 8 7 b c d 9 4 2 11 14 e a i 4 7 6 10 8 h g f 1 2
  • 19. 8 7 b c d 9 4 2 a 11 14 e i 4 7 6 10 8 h g f 1 2 8 7 b c d 9 4 2 a 11 14 e i 4 7 6 10 8 h g f 1 2 19
  • 20. 8 7 b c d 9 4 2 a 11 14 e i 4 7 6 10 8 h g f 1 2 8 7 b c d 9 4 2 a 11 14 e i 4 7 6 10 8 h g f 1 2 20
  • 21. 8 7 b c d 9 4 2 a 11 14 e i 4 7 6 10 8 h g f 1 2 8 7 b c d 9 4 2 a 11 14 e i 4 7 6 10 8 h g f 1 2 21
  • 22. 8 7 b c d 9 4 2 a 11 14 e i 4 7 6 10 8 h g f 1 2 8 7 b c d 9 4 2 a 11 14 e i 4 7 6 10 8 h g f 1 2 22
  • 23. 8 7 b c d 9 4 2 a 11 14 e i 4 7 6 10 8 h g f 1 2 MINIMAL SPANNING TREEE 8 7 b c d 9 4 2 a 11 14 e i 4 7 6 10 8 h g f 1 2 23
  • 24. Initialization O(V) time  Sorting the edges Q(E lg E) = Q(E lg V) (why?)  O(E) calls to FindSet  Union costs  Let t(v) – the number of times v is moved to a new cluster  Each time a vertex is moved to a new cluster the size of the cluster containing the vertex at least doubles: t(v) log V  Total time spent doing Union vV  t (v)  V log V  Total time: O(E lg V) 24
  • 25. Where ever the minimum distance is needed to achieve there this algorithm gets place.  For example.  In telephone lining under the ground, they have to connect all the cities with the minimum amount of wire.  If the new connection is in position to add between cities, there we have to consider the minimum cost distance.  Assume, if the minimum distance is not calculated, the wastage of wires will be in peak.
  • 26. Railways track construction.  National highway construction.  Flyover bridge construction.  Network between two intranets.  The another non-technical example will be as,  The by-pass rider or point to point buses will move on with the minimum distance path to reach the destination much faster. They will never circulate their bus through unwanted towns and villages.