Kruskal’s algorithm
This is an algorithm to solve the MST problem. It uses the union-find data structure to help it identify cycles.
Pseudocode
Kruskal's(G,w):
Input: undirected graph G=(V,E) with weights w(e).
Output: MST edges X
1. Sort E by weights, smallest to largest
2. Set X to be empty
3. For e = (v,w) in E (ordered)
1. If X U e does't have a cycle then X = X U e.
4. Output X
Run time
For step 1, we use merge sort so this takes
Step 3, has
So in total this takes
Correctness
We prove by induction on the size of
Base case
Note there must be an MST
Induction case
Suppose
Suppose we want to add some edge
This forms cut
Therefore by the cut property
This proves the induction case and we have that
Conclusion
As the algorithm considers adding every edge and adds it if and only if it doesn’t add cycle the output is a spanning tree. This is also minimal as