Build a Union-Find

union by size and path compression

Challenge 3 of GraphsIntermediate~55 minFree

Build a Disjoint Set Union step by step. Find, union, union by size, path compression, and component counting, then apply it to count friend circles the way network connectivity and Kruskal’s MST do.

5 steps

  1. 1Roots and find
  2. 2Union two sets
  3. 3Union by size
  4. 4Path compression and connected
  5. 5Counting components (friend circles)
Start step 1