Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 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