Abstract
When tracking grouping properties across dynamic networks—such as monitoring unified components or tracking connections in real time—standard graph traversals like DFS or BFS carry massive overhead costs if invoked repeatedly. The Disjoint Set Abstract Data Type (ADT) solves this constraint by maintaining isolated subsets under an optimization model that merges groups and checks path connectivity in near-constant execution time.
Category: Tree-based ADT (Up-Tree Forest)
Stores: A mathematical partition of elements split into disjoint subsets, where each group is managed by a unique representative node.
Built on top of: Plain standard sequential arrays.
Typical use cases: Dynamic cycle tracking inside Kruskal’s Algorithm, image segmentation tracking, network component clustering.
Core Structure
The absolute most space-efficient mechanism to realize a Disjoint Set ADT is the Up-Tree. Unlike a traditional standard tree layout where parent references point down to their child arrays, nodes inside an Up-Tree point upward to their parent targets.
- Sentinel Root Nodes: The absolute top representative node of a subset acts as the “name” of that group. A node pointing to itself or tracking a negative size flag is identified instantly as a root.
- Array Allocation Trick: Because every node points strictly to a single parent node, an entire Up-Tree forest can be packed inside a single 1D flat integer array (
parent[]). The index maps the item ID, and the slot value tracks its parent index. Ifparent[i] < 0, nodeiis determined to be a root.


Key Idea
Attaching the shorter (or smaller) tree under the taller (or larger) one during Union, plus flattening paths during Find, is what keeps the whole structure close to constant-time per operation despite each individual tree technically being able to grow.
Properties
- Invariant(s): The structure remains a strict forest of Up-Trees. Every non-root entry references exactly one parent, and chasing those upward references from any node guarantees hitting a root sentinel in finite iterations without encountering infinite cyclic traps.
- Shape Guarantee: Enforcing smart Union balances caps the worst-case tree height at . Interlocking this with explicit Path Compression drops the long-term amortized runtime per operation down to a near-constant , where is the Inverse Ackermann Function.
- Space Complexity: Strict linear allocation to store parent paths and structural tracking statistics.
- What it does NOT guarantee: Does not preserve an internal sorted element sequence; cannot easily split or partition a single group back into isolated elements once a merge is committed; cannot list all items inside a specific set without reading the entire array tracking scope.
Why the Invariant Holds
Lemma 1: Ranks Match Heights
If an Up-Tree vertex maintains an independent rank value , the actual maximum height of its structural branch under clean union balancing is exactly .
- Proof by Induction: A singleton item begins at rank 0 and height 0. Assume every rank- node bounds a maximum branch height of . A root can only climb to rank if a
Unioncommand attempts to merge two roots of identical rank . One root becomes a child of the other, incrementing the height of the newly formed root structure to exactly .
Lemma 2: Rank Sizes Grow Exponentially
An Up-Tree root vertex holding rank is guaranteed to contain at least total elements within its underlying tree partition.
- Proof by Induction: A root node at rank 0 holds at least item. Assume a rank- root bounds at least entries. To scale a tree to rank , we must merge two individual rank- component trees. Summing their independent boundaries yields: elements.
Theorem: Maximum Tree Height is Logarithmic
Given a total dataset constraints layout of elements, any vertex reaching rank would demand an explicit footprint size of at least elements according to Lemma 2. There is mathematically zero physical room left inside the array allocations to grow a rank higher than this value. Paired with Lemma 1, this caps the structural height bounds of an Up-Tree at when using Rank Balancing.
Data Structure Operations
Makeset(x)
Instantiates an independent item as its own singleton group partition.
Algorithm 47 Makeset Initialization
procedure Makeset()
Find(x)
Chases the parent array pointers upward to discover the core root representative of item .
- Time Complexity: worst-case under raw balancing; drops instantly to an amortized when Path Compression is active.
Algorithm 48 Find with Path Compression
procedure Find()
if then
return
Find()
return
Path Compression Optimization
Every single invocation of Find(x) maps out a clear path up to the root node. Path compression optimizes this path: as the recursive execution unrolls, it rewrites the parent pointers of every single node encountered along the search track to point directly to the top root node.

Traversal track passes through nodes (B, F) to reach root.

Resulting Flattened Topology: Future searches along this track hit in time.
Union(x, y)
Merges the complete tree sets containing elements and by linking the root node of the smaller collection beneath the root node of the larger collection.
Algorithm 49 Union by Rank
procedure Union()
Find()
Find()
if then
if then
else
if then
Union Variants
Union-by-Size
Always routes the parent index of the root with fewer nodes to point directly to the root bounding a larger size footprint.
- Storage Optimization: Can be cleanly packed inside a single tracking array. A root tracking value of
-5signifies a sentinel node leading a group component size of exactly 5 nodes. This completely eliminates the need for an independent auxiliary tracking array.

Union-by-Rank (Height)
Always binds the shorter tree beneath the root node of the taller tree structure.
- Gotcha: Once Path Compression starts flattening branches during execution lookups, “rank” shifts from tracking literal, active tree heights to acting as a fixed upper bound on potential height metrics.
Common Pitfalls
The Linear Chain Degeneration Danger
If you naively implement
Unionby blindly mapping root to point to root without evaluating rank or size metrics, a sequence of skewed inputs can collapse your Up-Trees into long, single-file linear chains. This spikes the operational height to , breaking all efficiency guarantees.
- Direct Parent Comparisons: Evaluating raw pointer structures via
parent[u] == parent[v]to confirm group connectivity will fail silently. You must explicitly evaluate paths through the full lookup pipeline:Find(u) == Find(v).
Tradeoffs Compared to Other Data Structures
| Structure | Check Connectivity | Merge Groups | Computational Advantage |
|---|---|---|---|
| Up-Tree Forest | amortized | amortized | High-efficiency lookup for asymmetric collections. |
| Standard BFS/DFS Passes | Simple architecture, but too slow for heavy interleaving lookups. | ||
| Hash Set Map Registries | worst-case | Supports listing set elements, but incurs high merge overhead. |
Related Notes
- Minimum Spanning Trees — Relies completely on this structure to catch cyclic edge violations inside Kruskal’s verification loop.
- Graph Representations — Explains the sequential flat array layouts used to build basic Up-Tree architectures.