---
title: Disjoint-set Tree
url: https://www.emergentmind.com/topics/disjoint-set-tree
type: topic
---

# Disjoint-set Tree

A disjoint-set tree is a data structure central to the implementation of dynamic connectivity algorithms, supporting efficient union and find operations on a collection of disjoint sets. In the context of disjoint-set forests, the most prevalent realizations are Union-Find trees that employ merging heuristics such as union-by-rank and perform path compression to improve amortized time complexity. The precise structural characterization and computational complexity of recognizing such trees, especially under union-by-rank with path-compression, involve deep combinatorial and complexity-theoretic insights [1704.07254].

## 1. Formal Definition of Ranked and Union-Find Trees

A **ranked tree** is defined as the quadruple
$$
t = (V_t, \mathsf{root}_t, \mathsf{rank}_t, \mathsf{parent}_t)
$$
where
- $V_t$ is a finite set of nodes,
- $\mathsf{root}_t \in V_t$ is the root node,
- $\mathsf{rank}_t: V_t \rightarrow \{0,1,2,\dots\}$ maps each node to a nonnegative integer rank,
- $\mathsf{parent}_t: V_t \setminus \{\mathsf{root}_t\} \rightarrow V_t$ gives each non-root node its parent.

The tree must satisfy the **rank-monotonicity** condition:
$$
\mathsf{rank}_t(x) < \mathsf{rank}_t(\mathsf{parent}_t(x)), \quad \text{for every } x \neq \mathsf{root}_t.
$$

Two operations are fundamental:
- **Merge (union-by-rank):** When merging disjoint trees $t$ and $s$ with $\mathsf{rank}(t) \geq \mathsf{rank}(s)$, the root of $s$ becomes a child of the root of $t$. If $\mathsf{rank}(t) = \mathsf{rank}(s)$, the new root's rank is incremented by one.
- **Path compression (collapse):** For a tree $t$ and a node $x$, $\mathsf{collapse}(t,x)$ reattaches all ancestors of $x$ (higher in the tree) directly under the root, without modifying ranks.

A **Union tree** is any ranked tree built from singleton rank-0 trees by repeated merges. Equivalently, $t$ is a Union tree if every node $v$ has exactly one child for each rank in $\{0,1,\dots,\mathsf{rank}(v)-1\}$.

A **Union-Find tree** is the closure (from singletons) under merges and collapses. This combination models the standard practice for efficiency in disjoint-set data structures [1704.07254]. 

## 2. Structural Characterization Using "Push" Operations

To structurally characterize which ranked trees are Union-Find trees (i.e., can result from merges and path-compressions), the "push" operation is introduced. Let $t$ be a ranked tree, and $x \neq y$ be siblings under the same parent with $\mathsf{rank}_t(x) < \mathsf{rank}_t(y)$. The **push** $(t, x, y) = t'$ modifies $t$ so that $x$ becomes a child of $y$, with all other parent/rank data unchanged.

Formally, the **push relation** $t \vdash t'$ denotes a single such operation, and $\vdash^*$ its reflexive-transitive closure.

**Structural equivalence theorem (Theorem 3):**
A ranked tree $t$ is a Union-Find tree if and only if 
$$
t \vdash^* s
$$
for some Union tree $s$ on the same nodes, root, and rank function. Thus, any Union-Find tree can be transformed into a Union tree through a sequence of "pushes," capturing the effect of path-compression but on the tree shape only [1704.07254].

## 3. Complexity of Recognizing Union-Find Trees

The decision problem **UNION-FIND-TREE** is defined as:
Given a ranked tree $\;t=(V,\mathsf{root},\mathsf{rank},\mathsf{parent})$ satisfying rank-monotonicity, is $t$ a Union-Find tree under the union-by-rank and path-compression strategy?

Recognition is shown to be **NP-complete**.

### NP-hardness (Sketch):

A reduction from the strongly NP-complete **PARTITION** problem constructs a "flat tree" whose structure encodes the partition constraints:
- Immediate children of the root include
  1. a gadget of three subtrees of ranks 0, 1, 2,
  2. $m$ "apples" of weight $a_i$: subtrees of rank 2 with $a_i$ children of rank 1 and one child of rank 0,
  3. $k$ "baskets": subtrees of rank 3 with $H+1$ children of rank 0 and a single special child of rank 1 (with its own rank 0 child).

Via the push operation, a successful transformation into a Union tree corresponds precisely to solving the PARTITION instance.

A key lemma (Proposition 7): in every Union-Find tree $u$,
$$
\#\{\text{rank } 0\} \geq \#\{\text{rank} > 0\},
$$
which enforces the combinatorics of the packing [1704.07254].

### Membership in NP:

Given the push characterization, a nondeterministic guess of at most $n^2$ pushes (where $n=|V|$) suffices; checking each push and final verification of the Union tree property is polynomial time. Thus the problem lies in NP.

**Theorem:** Recognizing whether a given ranked tree is a Union-Find tree under union-by-rank is NP-complete [1704.07254].

## 4. Verification, Certification, and Further Complexity

A consequence of this hardness is that any run-time certifier that checks whether a given forest structure is valid under arbitrary merges and path compressions must, in the worst case, solve an NP-complete problem. Thus, fully automatic certification of arbitrary union-find implementations, under union-by-rank with path-compression, cannot be both general and polynomial-time [1704.07254].

Additionally, an open question is whether there exists a different merging heuristic (other than union-by-rank or union-by-size) that preserves the optimal $O(\alpha(n))$ amortized complexity while admitting polynomial-time recognition.

Another open problem concerns the **rank-unlabeled case**: the complexity of recognition when only the tree structure (not node ranks) is given, i.e., whether there exists a rank assignment making the tree derivable as a union-by-rank Union-Find tree.

## 5. Mathematical Consequences and Structural Richness

These findings establish that the combinatorial structure of all possible Union-Find forests with path compression is substantially more complex than that of Union trees (without path compression), the latter being well-understood. The richness of Union-Find trees arises from path-compression modifying ancestor-descendant relationships by creating complex dependencies among subtrees that cannot be decoded into a simple local condition (in contrast with the case without path-compression).

This result highlights the intersection of fine-grained data-structure analysis, complexity theory, and formal certification, suggesting ongoing research at the boundary of structural combinatorics and efficient algorithmic verification [1704.07254].

## 6. Summary Table: Classes of Disjoint-Set Trees

| Tree Class       | Operations Allowed                   | Recognition Complexity    |
|------------------|-------------------------------------|--------------------------|
| Union Trees      | Merge (union-by-rank/size), no path compression | Local, polynomial-time    |
| Union-Find Trees | Merge (union-by-rank/size), path compression | NP-complete               |

Union trees permit a structural local characterization, but the addition of path compression renders the recognition globally constrained and NP-complete [1704.07254].

Source: https://www.emergentmind.com/topics/disjoint-set-tree