本文へスキップ
製品デスクトップツールTASTECAD図面の確認TASTEFILESファイル管理TASTEFTPファイル転送TASTESSHリモートワークスペースTASTEZIP圧縮と展開TASTEWINMファイル管理開発ツールTASTECODERust 統合開発環境TASTESTUDIO統合開発・テスト環境TASTEETLデータ統合(ETL)サーバーTASTEREMOTEリモートデスクトップサーバーTASTEGEO空間情報サーバーTASTEMAILメールワークスペース投資TASTESTOCK株式自動売買デスクトップアプリはじめるダウンロードドキュメント購入すべての製品
マーケットプレイス
ニュース
技術ニュース今日の開発ニュース開発ドキュメントプログラミング言語RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDartWebフロントエンド フレームワークNext.jsReactVue.js · NuxtSvelteKitAngularサーバー フレームワークSpring BootDjangoFastAPIASP.NET CoreNestJS · Expressアプリ・デスクトップ フレームワークTauriFlutterReact NativeElectronアルゴリズムアルゴリズムの基礎主要アルゴリズム発展アルゴリズム実務のアルゴリズム
コミュニティプロジェクト開発ログプロンプトAIツールの問題ショーケースコミュニティガイド
協業技術移転ウェブサイト構築デスクトップアプリ構築リリース・決済パイプライン販売パートナーお問い合わせ
サービスリモートデスクトップインストールパッケージのカスタマイズ
TASTEDEV
製品

デスクトップツール

TASTECAD複雑な図面を、軽やかにひらくTASTEFILES必要なファイルだけを、最速でTASTEFTPファイルが行き交う、いちばん端正な道TASTESSHサーバーとあなたを、より確かにつなぐTASTEZIPより速くまとめ、より安全にひらくTASTEWINM2つの画面で整理する、キーボード中心のファイルマネージャー

開発ツール

TASTECODERust アプリの編集・ビルド・デバッグ・テストまでひとつのウィンドウでTASTESTUDIO編集からリモートテスト、承認した AI 修正までTASTEETL値を見ながら、データを運ぶ

サーバー

TASTEREMOTE自社サーバーで運用するリモートデスクトップTASTEGEOGeoServer 互換の空間情報サーバーを Rust で作り直しますTASTEMAILメールの主導権を、もう一度自分の手に

投資

TASTESTOCKいつ・何を。自分で決めたルールどおりに動く株式自動売買

はじめる

ダウンロード全製品の最新版ドキュメント各製品の使い方購入サブスクリプション・永久ライセンスすべての製品全製品を一覧で
すべての製品
マーケットプレイスニュース
技術

ニュース

今日の開発ニュース言語・フレームワーク・GitHub・AI の公式発表開発ドキュメント言語・フレームワーク・アルゴリズムのガイド

プログラミング言語

RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDart

フレームワーク

Webフロントエンド フレームワークNext.jsReactVue.js · NuxtSvelteKitAngular
サーバー フレームワークSpring BootDjangoFastAPIASP.NET CoreNestJS · Express
アプリ・デスクトップ フレームワークTauriFlutterReact NativeElectron

アルゴリズム

アルゴリズムの基礎計算量解析 · ソート · 探索 · 基本データ構造 · 木構造とヒープ主要アルゴリズムグラフ探索 · 最短経路と最小全域木 · 動的計画法 · 貪欲法 · 分割統治法 · バックトラッキング発展アルゴリズム文字列アルゴリズム · 数学と整数論 · ビット演算 · セグメント木 · Union-Find実務のアルゴリズムコーディング面接対策 · LRUキャッシュ · レート制限 · コンシステントハッシュ法
開発ドキュメントをすべて見る
コミュニティ
プロジェクトビルダーと作品を探す開発ログ決定と試行錯誤プロンプト再利用できる指示AIツールの問題Claude・Codex・Gemini の問題と回避策ショーケース完成した成果コミュニティガイドオープンにつくる方法
協業
技術移転Rust・egui でネイティブアプリを作るウェブサイト構築10言語、アカウント、ドキュメントとダウンロードデスクトップアプリ構築Rust・egui、WebView なしリリース・決済パイプライン署名・MSI・deb・rpm・AppImage・ハッシュ販売パートナー紹介して決済額の30%お問い合わせ構築・提携・投資のご相談
サービス
リモートデスクトップブラウザから自分のパソコンへインストールパッケージのカスタマイズ必要な機能だけ、設定は事前に
購入
JA
한국어EnglishDeutschEspañolFrançaisItalianoPortuguês (Brasil)日本語简体中文繁體中文
ログイン
ログイン
TASTEDEV

小さなツールから、より良い開発へ。

support@tastedev.netTASTEDEVを支援
製品製品ラインナップ購入ドキュメントダウンロードマーケットプレイスサポート
コミュニティプロジェクト開発ログプロンプトAIツールの問題ショーケース
ポリシー会社概要プライバシーポリシー利用規約サブスクリプション規約返金ポリシーコミュニティガイドライン
アカウントログイン新規登録
訪問者
今日
昨日
累計閲覧
商号
GXSOFT
代表者
CHOI YOUNG GU
事業者登録番号
853-44-00368
所在地
9F V24, 351 Gyeongin-ro, Michuhol-gu, Incheon, Republic of Korea
電話
+82-10-4404-1523
メール
whitecalvin@tastedev.net
個人情報保護責任者
CHOI YOUNG GU

© 2026 TASTEDEV製品情報は検証済みの開発ソースに基づいています。リリース・改善中

Union-Find ドキュメント
Union-Find
Concepts: Disjoint Sets and Union-FindHow It Works: Tracing find and unionImplementation: Building a DSU ClassComplexity: Inverse Ackermann in Plain WordsPractice ProblemsReal-World Use and Pitfalls
ディスカッション

Union-Find ガイド · 6/6

Real-World Use and Pitfalls

この章は現在、英語でのみ提供しています。

Union-find is not just an interview data structure. It lives inside graph libraries, image processing, compilers and data-cleaning pipelines. This chapter shows how real libraries expose it, lists common mistakes, and points to further reading.

Union-find in libraries

Before writing your own, check whether a library you already use provides one.

  • SciPy: scipy.cluster.hierarchy.DisjointSet (since SciPy 1.6) accepts any hashable object as an element, not just integers.
  • NetworkX: networkx.utils.UnionFind is used internally, for example by its Kruskal minimum spanning tree implementation.
  • Boost: the C++ Boost Graph Library provides boost::disjoint_sets, used for incremental connected components.
  • Image processing: connected-component labeling such as scikit-image's label or OpenCV's connectedComponents relies on the same idea to merge provisional labels in the classic two-pass algorithm.
from scipy.cluster.hierarchy import DisjointSet

ds = DisjointSet(["a", "b", "c", "d"])
ds.merge("a", "b")
ds.merge("c", "d")
print(ds.connected("a", "c"))   # False
ds.add("e")
ds.merge("b", "e")
print(sorted(map(sorted, ds.subsets())))  # [['a', 'b', 'e'], ['c', 'd']]

Where it shows up in real systems

  • Networks and infrastructure: tracking which devices can reach each other as links are added.
  • Data cleaning and entity resolution: grouping records that share a phone number, email or device ID into one customer.
  • Compilers and type checkers: unification in type inference and Steensgaard-style points-to analysis merge things proven to be "the same" with union-find.
  • Physics simulations: percolation experiments open random grid cells and check whether the top and bottom have become connected.
  • Clustering: merging every pair of points closer than a threshold gives the same result as single-linkage clustering.

Handling string keys

Real data rarely comes with integer keys. Number each new key with a dictionary and the array-based DSU works unchanged.

class KeyedDSU:
    def __init__(self):
        self.index, self.parent, self.size = {}, [], []

    def _id(self, key):
        if key not in self.index:
            self.index[key] = len(self.parent)
            self.parent.append(len(self.parent))
            self.size.append(1)
        return self.index[key]

    def find(self, key):
        x = self._id(key)
        while self.parent[x] != x:
            self.parent[x] = self.parent[self.parent[x]]
            x = self.parent[x]
        return x

    def union(self, a, b):
        ra, rb = self.find(a), self.find(b)
        if ra == rb:
            return False
        if self.size[ra] < self.size[rb]:
            ra, rb = rb, ra
        self.parent[rb] = ra
        self.size[ra] += self.size[rb]
        return True

d = KeyedDSU()
d.union("phone:555-0100", "mail:kim@x.io")
d.union("mail:kim@x.io", "device:A7")
print(d.find("phone:555-0100") == d.find("device:A7"))  # True
この章について質問がありますか?
前の章Practice Problems

Common pitfalls

  • Linking non-roots: writing parent[a] = b corrupts the sets. Always link the roots returned by find.
  • Comparing parents to test membership: parent[a] == parent[b] can be wrong before paths are compressed. Always use find(a) == find(b).
  • One-based numbering: if vertices are numbered from 1, allocate n+1 slots or subtract 1.
  • Deep recursion: a recursive find in Python raises RecursionError on large inputs. Use a loop.
  • Deletion and undo: the basic structure cannot split sets. If you need undo, use a rollback DSU, which drops path compression and records each change on a stack.
class RollbackDSU:
    def __init__(self, n):
        self.parent, self.size, self.history = list(range(n)), [1] * n, []

    def find(self, x):            # no path compression, so changes stay undoable
        while self.parent[x] != x:
            x = self.parent[x]
        return x

    def union(self, a, b):
        ra, rb = self.find(a), self.find(b)
        if self.size[ra] < self.size[rb]:
            ra, rb = rb, ra
        self.history.append((rb, ra) if ra != rb else None)
        if ra != rb:
            self.parent[rb] = ra
            self.size[ra] += self.size[rb]

    def rollback(self):
        last = self.history.pop()
        if last:
            rb, ra = last
            self.parent[rb] = rb
            self.size[ra] -= self.size[rb]

Summary

Union-find already powers SciPy, NetworkX and Boost, as well as image labeling, type inference and data cleaning. Three habits prevent most bugs: link roots, compare with find, and implement find with a loop. When you need undo, reach for a rollback DSU.

Further reading

  • Disjoint-set data structure (Wikipedia)
  • Disjoint Set Union (cp-algorithms)
  • Case Study: Union-Find (Algorithms, 4th Edition)
  • Union-Find Disjoint Sets (VisuAlgo)
  • scipy.cluster.hierarchy.DisjointSet
  • Kruskal's algorithm (Wikipedia)

コメント 0件

人気のコメント順新しい順

ログイン · ログインするとコメントできます。