0% found this document useful (0 votes)
24 views

MST Construction Using Kruskal's Algorithm Kruskal's Algorithm Time Complexity Analysis

Kruskal's algorithm constructs a minimum spanning tree (MST) by sorting the edges by weight and iteratively adding edges in order of increasing weight, if the edge does not create a cycle. It runs in O(E log E) time, where E is the number of edges. The key steps are: 1) Sort edges by weight from lowest to highest. 2) Add the lowest weight edge that does not create a cycle to the MST. 3) Repeat step 2 until all vertices are connected in the MST.

Uploaded by

revathi
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

MST Construction Using Kruskal's Algorithm Kruskal's Algorithm Time Complexity Analysis

Kruskal's algorithm constructs a minimum spanning tree (MST) by sorting the edges by weight and iteratively adding edges in order of increasing weight, if the edge does not create a cycle. It runs in O(E log E) time, where E is the number of edges. The key steps are: 1) Sort edges by weight from lowest to highest. 2) Add the lowest weight edge that does not create a cycle to the MST. 3) Repeat step 2 until all vertices are connected in the MST.

Uploaded by

revathi
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Kruskal’s Algorithm

 MST construction using Kruskal’s algorithm


 Kruskal’s Algorithm
 Time complexity Analysis
Kruskal’s algorithm
Step-1: Sort all the edges from low weight to high weight.

Step-02: Take the edge with the lowest weight and use it to connect
the vertices of graph.

If adding an edge creates a cycle, then reject that edge and


go for the next least weight edge.

 Step-03: Keep adding edges until all the vertices are connected and
a Minimum Spanning Tree (MST) is obtained..
Construct MST for the given graph using Kruskal’s algorithm
•C
Since all the vertices
have been included in
the MST, so we stop.

Saveetha Engii
• MST_KRUSKAL(G)

• for each vertex v in V[G]


     do define set S(v) ← {v}
Initialize priority queue Q that contains all edges of G, using the weights as keys
A ← { }                    ▷ A will ultimately contains the edges of the MST
while A has less than n − 1 edges
    do Let set S(v) contains v and S(u) contain u
        if S(v) ≠ S(u)
            then Add edge (u, v) to A
                    Merge S(v) and S(u) into one set i.e., union
return A
Analysis
• The edge weight can be compared in constant time.

• Initialization of priority queue takes O(E lg E) time by


repeated insertion.
• At each iteration of while-loop, minimum edge can be
removed in O(log E) time, which is O(log V), since graph
is simple.
• The total running time is O((V + E) log V), which is
O(E lg V) since graph is simple and connected.
Assignment
Construct MST for the following graph using Kruskal’s algorithm

You might also like