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

Teile und herrsche-Dokumentation
Teile und herrsche
Divide and Conquer: Core ConceptsHow It Works: Step-by-Step TracesImplementation: Inversions and Fast PowerComplexity: Recurrences and the Master TheoremPractice ProblemsDivide and Conquer in the Real World
Diskussionen

Teile und herrsche-Anleitung · 4/6

Complexity: Recurrences and the Master Theorem

Dieses Kapitel ist vorerst nur auf Englisch verfügbar.

The running time of a divide-and-conquer algorithm is described by a recurrence: the cost of a call equals the cost of its recursive calls plus the cost of dividing and combining. This chapter shows how to solve such recurrences and compares the classic algorithms with their alternatives.

Writing a recurrence

If an algorithm splits an input of size n into a subproblems of size n/b and spends f(n) on dividing and combining, then T(n) = a * T(n/b) + f(n). Merge sort makes two half-size calls and merges in linear time, so T(n) = 2T(n/2) + O(n).

Draw the recursion tree to see the total. Merge sort's tree has log2 n levels and every level does n work in total:

level 0:  n                          -> n
level 1:  n/2  n/2                   -> n
level 2:  n/4  n/4  n/4  n/4         -> n
...       (log2 n levels)
total:    n * log2 n = O(n log n)

The master theorem

For T(n) = a * T(n/b) + f(n) with a >= 1 and b > 1, compare f(n) with n^c, where c = log_b(a) is the critical exponent: the number of leaves of the tree grows like n^c.

  1. If f(n) = O(n^d) for some d < c, the leaves dominate: T(n) = Θ(n^c).
  2. If f(n) = Θ(n^c * (log n)^k) for some k >= 0, every level costs about the same: T(n) = Θ(n^c * (log n)^(k+1)).
  3. If f(n) = Ω(n^d) for some d > c, and a * f(n/b) <= q * f(n) for some constant q < 1, the root dominates: T(n) = Θ(f(n)).
AlgorithmRecurrencec = log_b aCaseResult
Binary searchT(n/2) + O(1)02O(log n)
Fast exponentiationT(e/2) + O(1)02O(log e) multiplications
Merge sort, inversions2T(n/2) + O(n)12O(n log n)
Closest pair2T(n/2) + O(n)12O(n log n)
Karatsuba3T(n/2) + O(n)
Fragen zu diesem Kapitel?
Vorheriges KapitelImplementation: Inversions and Fast PowerNächstes KapitelPractice Problems
about 1.585
1
O(n^1.585)
Naive matrix multiplication8T(n/2) + O(n^2)31O(n^3)
Strassen7T(n/2) + O(n^2)about 2.8071O(n^2.807)
Quickselect, averageT(n/2) + O(n)03O(n) expected

Quickselect's worst case, T(n) = T(n - 1) + O(n) = O(n^2), does not fit the theorem because the subproblem shrinks by one element instead of a constant factor.

Karatsuba: three products instead of four

Split two numbers at m digits: x = x1 * 10^m + x0 and y = y1 * 10^m + y0. Then x * y = z2 * 10^(2m) + z1 * 10^m + z0, with z2 = x1 * y1, z0 = x0 * y0 and z1 = x1 * y0 + x0 * y1. Computing z1 directly needs two more products, giving 4T(n/2) and therefore O(n^2), no better than schoolbook multiplication. Karatsuba's trick is z1 = (x1 + x0) * (y1 + y0) - z2 - z0, which needs only one extra product. Three subproblems give O(n^log2(3)), about O(n^1.585).

def karatsuba(x, y):
    """Product of two non-negative integers with three recursive products."""
    if x < 10 or y < 10:
        return x * y
    m = max(len(str(x)), len(str(y))) // 2
    x1, x0 = divmod(x, 10 ** m)
    y1, y0 = divmod(y, 10 ** m)
    z2 = karatsuba(x1, y1)
    z0 = karatsuba(x0, y0)
    z1 = karatsuba(x1 + x0, y1 + y0) - z2 - z0
    return z2 * 10 ** (2 * m) + z1 * 10 ** m + z0

print(karatsuba(1234, 5678) == 1234 * 5678)  # True

Closest pair: why the strip is cheap

To find the closest pair among n points, sort them by x, split at the median x, and solve both halves to get d, the smaller of the two best distances. A closer pair must cross the dividing line, so both of its points lie in a strip of width 2d around it. Sort the strip by y; within that order each point only needs to be compared with a constant number of following points (at most 7), because more points than that cannot fit in a d by 2d box while staying d apart. The combine step is O(n) if the halves are merged by y as in merge sort, so T(n) = 2T(n/2) + O(n) = O(n log n). Re-sorting the strip at every level instead costs O(n log^2 n).

Counting the work

Counting operations is a quick way to check an analysis:

def count_mults(e):
    """Multiplications done by recursive fast power for exponent e."""
    if e == 0:
        return 0
    return count_mults(e // 2) + (2 if e % 2 else 1)

for e in (10, 1000, 10**6, 10**18):
    print(e, "naive:", max(e - 1, 0), "fast:", count_mults(e))

For e = 10^18 the naive method needs about 10^18 multiplications; fast power needs fewer than 120.

Comparison with alternatives

ProblemSimple approachDivide and conquerOther options
Counting inversionsAll pairs, O(n^2)Merge sort, O(n log n)Fenwick tree, O(n log n)
Power b^eRepeated multiplication, O(e)Fast power, O(log e)Built-in pow
k-th smallestSort, O(n log n)Quickselect, O(n) expectedMedian of medians, O(n) worst case; heap, O(n log k)
Big-number productSchoolbook, O(n^2)Karatsuba, O(n^1.585)FFT-based, about O(n log n)
Closest pairAll pairs, O(n^2)Strip method, O(n log n)Grid hashing, O(n) expected

Space matters too. Merge sort needs O(n) extra memory for merging, while recursion depth is O(log n) for balanced splits. Quickselect works in place but can recurse O(n) deep with bad pivots, which is why the loop form in the previous chapters is safer in Python.

Summary

  • Write T(n) = a * T(n/b) + f(n) and compare f(n) with n^log_b(a).
  • Equal cost on every level adds a log n factor; otherwise the leaves or the root dominate.
  • Karatsuba wins by turning four subproblems into three.
  • Shrinking by a constant factor matters: shrinking by one element gives quadratic time.

0 Kommentare

Top-KommentareNeueste zuerst

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