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

Union-Find の基本きほん

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

1導入どうにゅう

この講義こうぎでは、たがいに集合族しゅうごうぞくさだめる分割ぶんかつ定義ていぎし、find と union を提供ていきょうする Union-Find の表現ひょうげんおよび計算量けいさんりょう説明せつめいする。

2素集合分割そしゅうごうぶんかつ操作そうさ

集合しゅうごう U分割ぶんかつpartitionとは、くうでない部分集合族ぶぶんしゅうごうぞく [PARSE ERROR: Undefined("Command(\"mathcal\")")]P であって、ことなる二集合にしゅうごうたがいにであり、その和集合わしゅうごうU となるものである。Union-Find(disjoint-set union)は、この分割ぶんかつたいしてつぎ操作そうさ提供ていきょうする。

  • find(x) は、xふく集合しゅうごうてられた代表元だいひょうげんrepresentativeかえす。同一集合どういつしゅうごう要素ようそ同一どういつ代表元だいひょうげんをもち、find(x)=find(y)x,y同一集合どういつしゅうごうぞくすることは同値どうちである。
  • union(x,y) は、xyふく二集合にしゅうごう一集合いちしゅうごう併合へいごうする。すで同一集合どういつしゅうごうなら分割ぶんかつ変更へんこうしない。

初期状態しょきじょうたいでは、各要素かくようそ一要素集合いちようそしゅうごう構成こうせいするものとする。Union-Find は集合しゅうごう併合へいごう処理しょりするが、集合しゅうごう分割ぶんかつ要素ようそ削除さくじょ標準操作ひょうじゅんそうさふくまれない。

find と union の引数ひきすうU要素ようそであることを事前条件じぜんじょうけんとする。U=[PARSE ERROR: Undefined("Command(\"varnothing\")")]場合ばあい初期分割しょきぶんかつ空族くうぞくであり、有効ゆうこうな find または union の呼出よびだしは存在そんざいしない。

3おやもりによる表現ひょうげん

各集合かくしゅうごう根付ねつ表現ひょうげんし、全体ぜんたい根付ねつもりとして保持ほじする。各要素かくようそ xおや parent[x] をもち、 r では parent[r]=r とする。がその集合しゅうごう代表元だいひょうげんである。find はおや反復的はんぷくてき参照さんしょうして到達とうたつし、union はふたつの一方いっぽう他方たほうにする。

3.1経路圧縮けいろあっしゅく

find の実行中じっこうちゅう参照さんしょうした各頂点かくちょうてんおや変更へんこうする方法ほうほう経路圧縮けいろあっしゅくpath compressionという。分割ぶんかつ代表元だいひょうげん変更へんこうせず、後続こうぞくする find の親参照回数おやさんしょうかいすう削減さくげんする。

3.2ランクによる併合へいごう

たかさの上界じょうかいあらわランクrank保持ほじし、union でちいさいランクのおおきいランクのにする。同一どういつのランクなら一方いっぽうにし、あたらしいのランクを 1 増加ぞうかさせる。経路圧縮後けいろあっしゅくごのランクは実際じっさいたかさと一致いっちするとはかぎらないが、併合規則へいごうきそく使用しようできる。

4計算量けいさんりょう適用範囲てきようはんい

配列要素はいれつようそ参照さんしょう更新こうしんO(1) とする計算模型けいさんもけい仮定かていする。n 一要素集合いちようそしゅうごう初期化しょきかと、経路圧縮けいろあっしゅくおよびランクによる併合へいごう併用へいようした m かいの find・union からなる操作列そうされつ総時間そうじかんには、標準的ひょうじゅんてき簡略上界かんりゃくじょうかい O((n+m)α(n))使用しようできる。ここで αぎゃく Ackermann 関数かんすうである。より精密せいみつ表記ひょうきでは、その引数ひきすうnm双方そうほうからさだめる。この評価ひょうか操作列全体そうされつぜんたいたいするならし計算量けいさんりょうamortized complexityであり、各操作かくそうさ最悪時間さいあくじかん定数ていすうであることを意味いみしない。記憶領域きおくりょういきO(n) である。

無向むこうグラフへへん追加ついかするさい両端点りょうたんてんを union すれば、find の代表元だいひょうげん比較ひかくによって連結性れんけつせい管理かんりできる。ただし、Union-Find は連結経路れんけつけいろ最短路さいたんろ復元ふくげんせず、へん削除さくじょ直接ちょくせつには処理しょりしない。

Union-Find Basics

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
タブを全て閉じる