本文へスキップ
製品デスクトップツール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 ガイド · 4/6

Complexity: Inverse Ackermann in Plain Words

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

Union-find is often described as running in "nearly constant time". This chapter explains what that phrase really means, how the cost drops as each optimization is added, and how union-find compares with the alternatives.

Cost by optimization

Here n is the number of elements and m the number of find and union calls. union calls find twice internally, so it costs the same order as find.

ImplementationOne find (worst case)m operations in total
Quick-find (label array)O(1), but union is O(n)O(m n)
Plain trees (no optimization)O(n)O(m n)
Union by size or rank onlyO(log n)O(m log n)
Path compression onlyO(n), amortized O(log n)O(m log n)
BothO(log n)O(m α(n))

The α(n) in the last row is the inverse Ackermann function.

What is the inverse Ackermann function?

The Ackermann function grows unimaginably fast: nudge its input up a little and the output explodes. The inverse Ackermann function α(n) asks the opposite question: how large must the input be before the Ackermann function reaches n? Because the Ackermann function grows absurdly fast, α(n) grows absurdly slowly.

In plain words: even if you had far more elements than there are atoms in the observable universe, α(n) would still be at most 4. So the total cost O(m α(n)) can be read in practice as "a small constant per operation". Strictly speaking it is not a constant, and Tarjan showed that this bound cannot be beaten by any pointer-based structure of this kind.

Placing it next to the logarithm makes the difference obvious.

nlog2 nα(n)
164at most 3
65,53616at most 4
10^80 (roughly the atoms in the observable universe)about 266at most 4

What amortized means

With path compression, an individual find can still take a long time. But that find flattens the path it walked, so the calls that follow become cheaper. The cost is therefore measured as a total over all m operations rather than per call; this is amortized analysis. If the worst case of a single call matters, as in hard real-time systems, keep this in mind.

Seeing it for yourself

この章について質問がありますか?
前の章Implementation: Building a DSU Class次の章Practice Problems

The code below compares the deepest node in a tree built without optimizations against one built with both optimizations.

def depth(parent, x):
    d = 0
    while parent[x] != x:
        x = parent[x]
        d += 1
    return d

n = 1 << 12
naive = list(range(n))
for i in range(1, n):
    naive[i - 1] = i            # hang the previous root under the next element
print(max(depth(naive, x) for x in range(n)))   # 4095

parent, size = list(range(n)), [1] * n
def find(x):
    while parent[x] != x:
        parent[x] = parent[parent[x]]
        x = parent[x]
    return x
for i in range(1, n):
    ra, rb = find(i - 1), find(i)
    if size[ra] < size[rb]:
        ra, rb = rb, ra
    parent[rb] = ra
    size[ra] += size[rb]
print(max(depth(parent, x) for x in range(n)))  # 1

With union by size, each new singleton is hung directly under the root of the big tree, so the maximum depth stays at 1.

Timing operations

Run 200,000 random unions while growing the number of elements a thousandfold. The time per operation stays in the low microseconds and does not grow in proportion to n. Depending on your machine it may creep up a little, mostly because larger arrays fit less well in the CPU cache, not because the algorithm does more work.

import random
import time

def ns_per_op(n, m=200_000):
    parent, size = list(range(n)), [1] * n
    def find(x):
        while parent[x] != x:
            parent[x] = parent[parent[x]]
            x = parent[x]
        return x
    start = time.perf_counter()
    for _ in range(m):
        ra, rb = find(random.randrange(n)), find(random.randrange(n))
        if ra != rb:
            if size[ra] < size[rb]:
                ra, rb = rb, ra
            parent[rb] = ra
            size[ra] += size[rb]
    return (time.perf_counter() - start) / m * 1e9

for n in (10**3, 10**5, 10**6):
    print(n, f"{ns_per_op(n):.0f} ns/op")

Space complexity

Two arrays, parent and size (or rank), give O(n) space. Ranks never exceed log n, so a very small integer type is enough for them. A recursive find can push as many stack frames as the tree is tall in the worst case, so in languages with a low recursion limit, such as Python, the iterative version is the safe choice.

import sys
# If you must use a recursive find, you may need a higher limit
sys.setrecursionlimit(1 << 20)

def find_rec(parent, x):
    if parent[x] != x:
        parent[x] = find_rec(parent, parent[x])
    return parent[x]

Comparison with alternatives

ApproachAdd edgeConnectivity queryDelete edgeNotes
Union-findnearly O(1)nearly O(1)not supportedmerges only
BFS/DFS per queryO(1)O(V + E)O(1)simple when queries are rare
Precomputed componentsfull recomputeO(1)full recomputefor graphs that never change
Dynamic connectivity structuresO(log^2 n) amortizedO(log n)supportedcomplex to implement

Summary

With both optimizations, union-find runs m operations in O(m α(n)) time and O(n) space. Since α(n) is at most 4 for any realistic input, you can treat it as a constant. When edges are never deleted and queries are frequent, it is far more efficient than rerunning BFS or DFS.

コメント 0件

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

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