Connect components with disjoint-set union

8 steps · about 2 h 55 min · Intermediate

  1. Learn make, find and union (guide, CP-Algorithms, 25 min)

    Introduces the three operations and improves the basic forest one optimization at a time.

  2. Frame the dynamic-connectivity problem (reference, Princeton University, 20 min)

    Starts from a concrete connectivity API and compares several implementations by measured cost.

  3. Place union-find among graph structures (guide, Open Data Structures, 15 min)

    Connects the structure to component tracking and gives exercises that expose its limits.

  4. Visualize forest merging (interactive, University of San Francisco, 20 min)

    Makes parent links, ranks and compressed paths visible after every operation.

  5. Read a compact weighted implementation (guide, Princeton University, 20 min)

    A short reference implementation makes the parent and size invariants easy to annotate and test.

  6. Use components while building an MST (guide, Princeton University, 25 min)

    Kruskal's algorithm gives union-find a real job: reject edges whose endpoints are already connected.

  7. Find the edge that closes a cycle (interactive, GeeksforGeeks, 25 min)

    Applies find-before-union to detect exactly when an undirected graph stops being a forest.

  8. Count final connected components (interactive, GeeksforGeeks, 25 min)

    Checks initialization, repeated unions and correct counting of distinct roots on a small graph.