Zum Hauptinhalt springen
ProdukteDesktop-WerkzeugeTASTECADZeichnungsprüfungTASTEFILESDateiverwaltungTASTEFTPDateiübertragungTASTESSHRemote-ArbeitsbereichTASTEZIPKomprimieren und EntpackenTASTEWINMDateiverwaltungEntwicklerwerkzeugeTASTECODEIntegrierte Entwicklungsumgebung für RustTASTESTUDIOIntegrierte Entwicklungs- und TestumgebungTASTEETLDatenintegration (ETL)ServerTASTEREMOTERemote-Desktop-ServerTASTEGEOGeodatenserverTASTEMAILE-Mail-ArbeitsbereichInvestierenTASTESTOCKDesktop-App für automatischen AktienhandelErste SchritteDownloadsDokumentationKaufenAlle Produkte
Marktplatz
Neuigkeiten
TechnikNeuigkeitenEntwickler-News von heuteEntwicklerdokuProgrammiersprachenRustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDartWeb-Frontend-FrameworksNext.jsReactVue.js · NuxtSvelteKitAngularServer-FrameworksSpring BootDjangoFastAPIASP.NET CoreNestJS · ExpressApp- & Desktop-FrameworksTauriFlutterReact NativeElectronAlgorithmenAlgorithmus-GrundlagenKernalgorithmenFortgeschrittene AlgorithmenAlgorithmen für die Praxis
CommunityProjekteEntwicklungslogsPromptsProbleme mit KI-ToolsShowcaseCommunity-Leitfaden
ZusammenarbeitWissenstransferWebsite-AufbauDesktop-App-AufbauRelease- und ZahlungspipelineVertriebspartnerKontakt
DiensteRemote-DesktopIndividuelle Installationspakete
TASTEDEV
Produkte

Desktop-Werkzeuge

TASTECADKomplexe Zeichnungen, mühelos geöffnetTASTEFILESNur die Dateien, die zählen – in BestzeitTASTEFTPDer aufgeräumteste Weg für Ihre DateienTASTESSHDie stärkere Verbindung zu Ihren ServernTASTEZIPSchneller packen, sicherer entpackenTASTEWINMEin tastaturorientierter Dateimanager mit zwei Fenstern

Entwicklerwerkzeuge

TASTECODERust-Apps bearbeiten, bauen, debuggen und testen – alles in einem FensterTASTESTUDIOVom Bearbeiten bis zu Remote-Tests und freigegebenen KI-KorrekturenTASTEETLDaten bewegen, die Werte im Blick

Server

TASTEREMOTEEin Remote-Desktop auf Ihrem eigenen ServerTASTEGEOEin GeoServer-kompatibler Geodatenserver, neu aufgebaut in RustTASTEMAILIhre E-Mail wieder in Ihrer Hand

Investieren

TASTESTOCKAutomatischer Aktienhandel nach Ihren Regeln: wann und was

Erste Schritte

DownloadsNeueste Versionen aller ProdukteDokuSo nutzen Sie jedes ProduktKaufenAbos und DauerlizenzenAlle ProdukteAlle Produkte im Überblick
Alle Produkte
MarktplatzNeuigkeiten
Technik

Neuigkeiten

Entwickler-News von heuteOffizielle Meldungen zu Sprachen, Frameworks, GitHub und KIEntwicklerdokuAnleitungen zu Sprachen, Frameworks und Algorithmen

Programmiersprachen

RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDart

Frameworks

Web-Frontend-FrameworksNext.jsReactVue.js · NuxtSvelteKitAngular
Server-FrameworksSpring BootDjangoFastAPIASP.NET CoreNestJS · Express
App- & Desktop-FrameworksTauriFlutterReact NativeElectron

Algorithmen

Algorithmus-GrundlagenKomplexitätsanalyse · Sortieren · Suchen · Grundlegende Datenstrukturen · Bäume und HeapsKernalgorithmenGraphtraversierung · Kürzeste Wege und minimale Spannbäume · Dynamische Programmierung · Greedy-Algorithmen · Teile und herrsche · BacktrackingFortgeschrittene AlgorithmenZeichenkettenalgorithmen · Mathematik und Zahlentheorie · Bitmanipulation · Segmentbäume · Union-FindAlgorithmen für die PraxisStrategie für Coding-Interviews · LRU-Cache · Rate Limiting · Konsistentes Hashing
Alle Entwicklungsdokumente
Community
ProjekteEntwickler und Projekte entdeckenEntwicklungslogsEntscheidungen und ErkenntnissePromptsWiederverwendbare AnweisungenProbleme mit KI-ToolsProbleme und Workarounds für Claude, Codex, GeminiShowcaseFertige ErgebnisseCommunity-LeitfadenWie wir offen entwickeln
Zusammenarbeit
WissenstransferNative Apps mit Rust und eguiWebsite-Aufbau10 Sprachen, Konten, Dokumentation und DownloadsDesktop-App-AufbauRust und egui, ohne WebViewRelease- und ZahlungspipelineSignatur, MSI, deb, rpm, AppImage, PrüfsummenVertriebspartnerEmpfehlen und 30 % erhaltenKontaktEntwicklung, Partnerschaft, Investition
Dienste
Remote-DesktopIhren Computer im Browser erreichenIndividuelle InstallationspaketeNur nötige Funktionen, Einstellungen vorab
Kaufen
DE
한국어EnglishDeutschEspañolFrançaisItalianoPortuguês (Brasil)日本語简体中文繁體中文
Anmelden
Anmelden
TASTEDEV

Von kleinen Werkzeugen zu besserer Entwicklung.

support@tastedev.netTASTEDEV unterstützen
ProdukteProduktübersichtKaufenDokuDownloadsMarktplatzSupport
CommunityProjekteEntwicklungslogsPromptsProbleme mit KI-ToolsShowcase
RichtlinienÜber unsDatenschutzerklärungNutzungsbedingungenAbo-BedingungenRückerstattungCommunity-Richtlinien
KontoAnmeldenRegistrieren
Besucher
Heute
Gestern
Aufrufe gesamt
Firma
GXSOFT
Vertretungsberechtigt
CHOI YOUNG GU
Handelsregisternummer
853-44-00368
Anschrift
9F V24, 351 Gyeongin-ro, Michuhol-gu, Incheon, Republic of Korea
Telefon
+82-10-4404-1523
E-Mail
whitecalvin@tastedev.net
Datenschutzbeauftragter
CHOI YOUNG GU

© 2026 TASTEDEVProduktinformationen basieren auf verifizierten Entwicklungsquellen.Veröffentlicht · wird verbessert

Union-Find-Dokumentation
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
Diskussionen

Union-Find-Anleitung · 4/6

Complexity: Inverse Ackermann in Plain Words

Dieses Kapitel ist vorerst nur auf Englisch verfügbar.

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

Fragen zu diesem Kapitel?
Vorheriges KapitelImplementation: Building a DSU ClassNächstes KapitelPractice 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 Kommentare

Top-KommentareNeueste zuerst

Anmelden · Melde dich an, um einen Kommentar zu schreiben.