Brendan Ang

Search

Search IconIcon to open search

Kruskal's Algorithm

Last updated Nov 8, 2022 Edit Source

# Kruskal’s Algorithm

# General Idea

A greedy algorithm to generate a Minimum Spanning Tree using the Union Find data structure.

  1. Sort edges in increasing order of weight (a priority queue using a Heaps)
  2. Add the edge to the minimum spanning tree unless it creates a cycle
    • Cycle check uses union find

# Pseudocode

# Complexity

Time complexity is $O(ElogE)$ mainly due to the contribution of the Heaps implementation of priority queue to obtain the least cost edge.

# Examples

Manually: Update the id directly to the root (D) when connecting with other equivalence classes when using :