Computer ScienceData StructuresMedium

Disjoint Set

Also known as:Union-FindMerge-Find setDSU (Disjoint Set Union)

A disjoint set (also called union-find or merge-find set) is a data structure that keeps track of a collection of non-overlapping sets and supports two primary operations: Union (merging two sets) and Find (determining which set an element belongs to by returning a representative). With path compression and union by rank optimizations, operations run in nearly O(1) amortized time per operation (Inverse Ackermann function). Disjoint sets are foundational in Kruskal's minimum spanning tree algorithm, network connectivity checking, and image segmentation.

Disjoint Set Optimization Strategies

StrategyFind ComplexityUnion ComplexitySpace
Naive (no optimization)O(n)O(1)O(n)
Union by RankO(log n)O(log n)O(n)
Path CompressionO(log n) amortizedO(log n)O(n)
Both (Rank + Path Compression)O(α(n)) ≈ O(1)O(α(n)) ≈ O(1)O(n)

Interactive Tools

Visualgo — Union Find

Open Tool

CS USF — Union Find Visualization

Open Tool

Brilliant.org — Disjoint Set Union

Open Tool
A disjoint set (union-find) structure showing forest representation of sets

Wikimedia Commons, CC BY-SA

Related Terms

The term "disjoint set" derives from mathematical set theory, where "disjoint" (from Latin "disjunctus," separated) refers to sets with no elements in common. The alternative name "union-find" describes the two primary operations it supports. The data structure was developed by Bernard Galler and Michael Fischer in 1964.

union-finddisjoint-setgraphconnectivitydata-structurealgorithms