markdown
Union-Find Basicsmd 9329432
lecture/information/algorithm/data-structures/union-find-basics.lecture.n.md
Download PDF

Union-Find Basics

date2026-07-14document_iddoc_cd1649d271040841319f831533eb8352description素集合分割、find、unionを定義し、経路圧縮とランク併合を用いるUnion-Findの計算量を説明する。prerequisites木とヒープの基本 / グラフの基本 / 計算量の基本type講義statusactiverelateddata/lecture/information/algorithm/data-structures/data-structures-portal.lecture.n.md / data/lecture/information/algorithm/graph/graph-algorithms-portal.lecture.n.md
algorithmdata-structuresundergraduatelecture
data/lecture/information/algorithm/data-structures/tree-and-heap-basics.lecture.n.md data/lecture/information/graph/graph-basics.lecture.n.md

1Introduction

This lecture defines a partition into pairwise disjoint sets and explains the representation and complexity of Union-Find, which provides the find and union operations.

2Disjoint-set partitions and operations

A partition of a set U is a family [PARSE ERROR: Undefined("Command(\"mathcal\")")]P of nonempty subsets whose distinct members are pairwise disjoint and whose union is U. Union-Find, also called disjoint-set union, supports the following operations on such a partition.

  • find(x) returns the representative assigned to the set containing x. Elements in one set have the same representative, so find(x)=find(y) if and only if x and y belong to the same set.
  • union(x,y) merges the sets containing x and y. It leaves the partition unchanged if they are already the same set.

Initially, each element forms a singleton set. Union-Find supports merging sets; splitting a set and deleting an element are not standard operations.

Every argument to find or union must belong to U. If U=[PARSE ERROR: Undefined("Command(\"varnothing\")")], the initial partition is the empty family and there is no valid call to find or union.

3Parent-forest representation

Represent each set by a rooted tree and store the collection as a forest of rooted trees. Every element x has a parent parent[x], and a root r satisfies parent[r]=r. The root is the representative of its set. Find follows parent references to a root. Union makes one of two roots a child of the other.

3.1Path compression

Path compression changes the parent of every vertex visited by find to the root. It preserves the partition and representative while reducing the number of parent references in later find operations.

3.2Union by rank

Store at each root a rank that is an upper bound on tree height. Union makes the root of smaller rank a child of the root of larger rank. If their ranks are equal, it chooses either root as the child and increments the other root's rank. After path compression, rank need not equal actual height, but it remains suitable for the union rule.

4Complexity and scope

Assume that accessing or updating one array entry takes O(1) time. Initializing n singleton sets and then processing m find and union operations with path compression and union by rank admits the standard simplified upper bound O((n+m)α(n)), where α is the inverse Ackermann function. More precise notation defines its argument using both n and m. This is an amortized complexity bound over the whole sequence; it does not state that every operation has constant worst-case time. The structure uses O(n) space.

When an edge is added to an undirected graph, unioning its endpoints permits connectivity queries by comparing representatives returned by find. Union-Find does not reconstruct a connecting path or a shortest path, and it does not directly support edge deletion.

raw .n.md をコピー
loc をコピー (filepath:line ~ line)
copy share link
copy encoded share link
path をコピー
copy share link
copy encoded share link
copy share link
copy encoded share link
タブを全て閉じる