Union-find and Kruskal's MST, step by step

10 steps · about 3 h 7 min · Intermediate

  1. Union Find Introduction (video, William Fiset (YouTube), 10 min)

    It starts with the problem union-find solves: tracking which elements belong to the same group.

  2. Kruskal's algorithm, minimum spanning trees (article, algorithms-visual.com, 20 min)

    It walks through Kruskal's algorithm with pictures, so you see how find and union reject cycle-forming edges.

  3. Minimum Spanning Tree (Prim's, Kruskal's) - VisuAlgo (interactive, VisuAlgo, 20 min)

    You can run Kruskal's algorithm on your own graphs and watch the union-find checks happen.

  4. Union Find Kruskal's Algorithm (video, William Fiset (YouTube), 10 min)

    It ties the data structure back to the MST algorithm in a short worked example.

  5. Union Find Path Compression (video, William Fiset (YouTube), 10 min)

    It explains the key optimisation that keeps find fast, before you write any code.

  6. Disjoint Sets Visualization (interactive, David Galles' visualization (mirror), 15 min)

    You can experiment with union by rank and path compression and see the trees flatten.

  7. Union Find Code (video, William Fiset (YouTube), 12 min)

    Once the ideas are clear, you can follow a full implementation line by line.

  8. Minimum Spanning Tree - Kruskal with Disjoint Set Union (reference, cp-algorithms.com, 20 min)

    It gives compact working code and the O(M log N) running-time argument.

  9. williamfiset/algorithms (repo, GitHub (William Fiset), 25 min)

    You can read and run a well-tested union-find and Kruskal implementation in code, to compare with your own.

  10. 15-451: Algorithm Design and Analysis, Union-Find (article, Carnegie Mellon University, 45 min)

    It closes with the amortized-cost analysis of why union-find is nearly constant time.