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

Module 2b Kruskal

Uploaded by

Preeti Gupta
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Module 2b Kruskal

Uploaded by

Preeti Gupta
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 20

Amity School of Engineering and Technology

Amity School of Engineering &


Technology
B.Tech CSE, Semester 5
Analysis and Design of Algorithms

1
Solution to MST Problem

2
Solution to MST Problem

3
Kruskal’s Algorithm
• This is a greedy algorithm.

• A greedy algorithm chooses some local optimum (i.e.


picking an edge with the least weight in a MST).

• Kruskal requires a good sorting algorithm to sort


edges of the input graph by increasing weight

4
Kruskal Algorithm
Implementation
• Step 1

– Sort all the edges from low weight to high weight.

5
Kruskal Algorithm
Implementation
• Step 2

– 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.

6
Kruskal Algorithm
Implementation
• Step 3

– Keep adding edges until all the vertices are


connected and a Minimum Spanning Tree (MST)
is obtained.

7
Kruskal’s Algorithm

8
Kruskal’s Algorithm

9
Kruskal’s Algorithm

10
Kruskal’s Algorithm

11
Kruskal’s Algorithm

12
Kruskal’s Algorithm

13
Kruskal’s Algorithm

14
Kruskal’s Algorithm

15
Kruskal’s Algorithm

16
Kruskal’s Algorithm

17
Running Time

• O ( m log n)

– By implementing queue X as a heap , X could be


initialized in O (m) time and a vertex could be
extracted in each iteration in O ( log n ) time

18
Summary & Expected
Learning

19
References

• T. H. Cormen, Leiserson, Rivest and Stein, “Introduction of Computer algorithm,”


PHI Publication

• E. Horowitz, S. Sahni, and S. Rajsekaran, “Funadmentals of Computer


Algorithms,” Galgotia Publication

• https://nptel.ac.in/courses/106/101/106101060/

20

You might also like