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

Kürzeste Wege und minimale Spannbäume-Dokumentation
Kürzeste Wege und minimale Spannbäume
ConceptsHow it worksImplementationComplexityPractice problemsReal-world use
Diskussionen

Kürzeste Wege und minimale Spannbäume-Anleitung · 2/6

How it works

Dieses Kapitel ist vorerst nur auf Englisch verfügbar.

This chapter traces each algorithm on a small graph so you can see the order of relaxations. The Dijkstra example uses directed edges A→B 4, A→C 1, C→B 2, B→D 1, C→D 5, D→E 3 with source A.

Dijkstra step by step

Dijkstra keeps a min-heap of (distance, vertex) pairs. It repeatedly pops the closest vertex; because all weights are non-negative, no later path can make that vertex any cheaper, so its distance is final. It then relaxes the vertex's outgoing edges. When a distance improves we simply push a new pair instead of updating the old one; outdated pairs are skipped when popped ("lazy deletion").

PopABCDENote
start0infinfinfinfheap: (0,A)
(0,A)041infinfpush (4,B), (1,C)
(1,C)0316infB improves 4 to 3
(3,B)0314infD improves 6 to 4
(4,B)0314infstale, skipped
(4,D)03147push (7,E)
(6,D)03147stale, skipped
(7,E)03147heap empty

Final distances: A 0, B 3, C 1, D 4, E 7. The shortest path to E is A→C→B→D→E.

Why negative edges break Dijkstra

Take A→B 2, A→C 3, C→B -2. Dijkstra settles B at distance 2 before it looks at C, but the true distance is 3 + (-2) = 1. The greedy "closest is final" argument assumes that extending a path never makes it shorter, which is false with negative weights. Use Bellman-Ford instead.

Bellman-Ford

Bellman-Ford relaxes every edge, V - 1 times. A shortest path without cycles has at most V - 1 edges, and after round k every path of k edges has been accounted for. One extra round then acts as a test: if any edge can still be relaxed, a negative cycle is reachable from the source.

Fragen zu diesem Kapitel?
Vorheriges KapitelConceptsNächstes KapitelImplementation
from math import inf def bellman_ford(n, edges, source): dist = [inf] * n dist[source] = 0 for _ in range(n - 1): changed = False for u, v, w in edges: if dist[u] != inf and dist[u] + w < dist[v]: dist[v] = dist[u] + w changed = True if not changed: # early exit: nothing moved this round break for u, v, w in edges: if dist[u] != inf and dist[u] + w < dist[v]: raise ValueError("negative cycle reachable from source") return dist # S=0, A=1, B=2, C=3 print(bellman_ford(4, [(0, 1, 4), (0, 2, 5), (2, 1, -3), (1, 3, 2)], 0)) # [0, 2, 5, 4]

In round 1 the edges are scanned in the listed order: A becomes 4, B becomes 5, then B→A lowers A to 2, and A→C sets C to 4. Round 2 changes nothing, so the loop stops early.

Floyd-Warshall

Floyd-Warshall computes all pairs at once with a three-level loop. After processing intermediate vertex k, d[i][j] is the shortest path from i to j that uses only vertices 0..k in between. The order of the loops matters: k must be the outermost.

from math import inf

def floyd_warshall(d):
    n = len(d)
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if d[i][k] + d[k][j] < d[i][j]:
                    d[i][j] = d[i][k] + d[k][j]
    return d

d = [[0, 3, inf], [inf, 0, 1], [2, inf, 0]]
print(floyd_warshall(d))  # [[0, 3, 4], [3, 0, 1], [2, 5, 0]]

After the run, a negative value on the diagonal (d[i][i] < 0) means vertex i lies on a negative cycle.

0-1 BFS

When every weight is 0 or 1, a deque replaces the heap. A vertex reached by a 0-edge goes to the front, by a 1-edge to the back, so the deque always stays sorted by distance and each step is O(1).

from collections import deque
from math import inf

def zero_one_bfs(adj, source):
    dist = [inf] * len(adj)
    dist[source] = 0
    dq = deque([source])
    while dq:
        u = dq.popleft()
        for v, w in adj[u]:
            if dist[u] + w < dist[v]:
                dist[v] = dist[u] + w
                if w == 0:
                    dq.appendleft(v)
                else:
                    dq.append(v)
    return dist

print(zero_one_bfs([[(1, 1), (2, 0)], [(3, 1)], [(1, 0), (3, 1)], []], 0))  # [0, 0, 0, 1]

Kruskal and Prim on one graph

Undirected edges: A-B 1, B-C 2, A-C 3, C-D 4, B-D 5.

Kruskal (sorted edges)DecisionTree weight
A-B 1take, joins two components1
B-C 2take3
A-C 3skip, A and C already connected3
C-D 4take, now V - 1 = 3 edges7

Prim from A pops the cheapest edge that leaves the tree: A-B 1, then B-C 2 (cheaper than A-C 3), then C-D 4 (cheaper than B-D 5). Both reach the same tree of weight 7. They can pick different trees only when equal weights allow several MSTs, and the total is always the same.

Summary

  • Dijkstra settles the closest vertex each time and skips stale heap entries.
  • Bellman-Ford needs V - 1 rounds; a change in an extra round means a negative cycle.
  • Floyd-Warshall loops over intermediate vertices k, outermost.
  • 0-1 BFS keeps the deque ordered by pushing 0-edges to the front.
  • Kruskal works edge by edge, Prim grows a single tree; both are greedy and both are correct.

0 Kommentare

Top-KommentareNeueste zuerst

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