next up previous contents
Next: Dikstra's Algorithmus mit Radix-Heaps Up: Das single-source-shortest-path-Problem Previous: Das single-source-shortest-path-Problem

Dijkstra's Algorithmus

$\textstyle\parbox{70mm}{
\textbf{Gegeben:} $G=(V,A), (A=V \times V),$\space Dis...
 ...p\{+\infty\}$. Startknoten $s$. $G$\space durch Adjazenzlisten dargestellt.\\ }$


\begin{picture}
(31,31)
 \bezier{20}(10,20)(20,20)(20,10)
 \bezier{20}(20,10)(20...
 ... \put(5,0){\makebox(5,4)[tl]{s}}
 \put(2.5,6){\makebox(5,4)[bl]{0}}\end{picture}

algorithm sssp:=


$\ulcorner$$S:=\{s\}$; dis[s]:=0; initialisiere eine Priorityqueue PQ, die alle Knoten $v\in V\setminus\{s\}$ enthält mit Schlüssel dis$[v]:=\text{d}(s,v)$;for alle $v \in V-\{s\}$ do from[v]:=s od while $S \neq V$ do v:= ExtractMin(PQ); $S:= S \cup \{v\}$; for alle $w \in V-S$, d$(v,w)<\infty$ do if dis$[v] + \text{d}(v,w) < \text{dis}[w]$ then DecreaseKey(w, dis[v] + d(v, w)); co DecreaseKey verändert dis[w] oc from[w]:= v; fi od od $\llcorner$

Seien n=|V| und m:= Anzahl wirklicher Kanten:

Laufzeit (mit Fibonacci-Heaps):

Initialisierung: $\mathcal{O}(n)$
ExtractMin : $n \cdot \mathcal{O}(\log n)$
Sonstiger Aufwand: $m-\mathcal{O}(1)$ (z.B. DecreaseKey )



$ \Rightarrow $ Zeitbedarf also: \fbox {$\mathcal{O}(m + n \log n)$}

Korrektheit: Wir behaupten, daß in dem Moment, in dem ein $v \in V-\{s\}$Ergebnis der FindMin Operation ist, der Wert dis[v] des Schlüssels von v gleich der Länge eines kürzesten Pfades von s nach v ist.

Beweis: durch Widerspruch: Sei $v \in V-\{s\}$ der erste Knoten, für den diese Behauptung nicht stimmt und sei


\begin{picture}
(72,5)
 \multiput(1,1)(10,0){8}{\circle*{1}}
 \multiput(1,1)(10,...
 ...}}
 \put(67,0){\makebox(5,5)[tr]{$v$}}
 \put(61,1){\vector(1,0){9}}\end{picture}

ein kürzester Pfad von s nach v, mit einer Länge $< \text{dis}[v]$. Dabei sind $s_1,\ldots,s_r\in S$, $v_1 \notin S$ [r=0 und/oder q=0 ist möglich]. Betrachte Pfad
\begin{picture}
(32,5)
 \multiput(1,1)(10,0){4}{\circle*{1}}
 \multiput(1,1)(20,...
 ...,0){\makebox(5,5)[t]{$s_r$}}
 \put(27.5,0){\makebox(5,5)[t]{$v_1$}}\end{picture}
; seine Länge ist $< \text{dis}[v]$, für $q\geq 1$ (ebenso für q=0) ist also dis$[v_1] <\text{dis}[v]$, Widerspruch zur Wahl von v. $\Diamond$

Beispiel für Dijkstra-Algorithmus:


\begin{picture}
(168,55)

 \put(103,39){\makebox(65,5)[l]{gegeben Graph $G$;}}
 ...
 ... 4
 \put(65,47){\line(1,-1){20}}% 5
 \put(75,7){\line(1,2){10}} % 6\end{picture}


\begin{picture}
(168,55)

 \put(103,39){\makebox(65,5)[l]{markiere $(v_1,v_2)$;}...
 ...ine(1,-1){20}}% 5
 \put(75,7){\line(1,2){10}} % 6

\color {black}
 \end{picture}


\begin{picture}
(168,55)
 

 \put(103,45){\makebox(65,5)[l]{markiere $(v_2,v_3)$...
 ...ine(1,-1){20}}% 5
 \put(75,7){\line(1,2){10}} % 6

\color {black}
 \end{picture}


\begin{picture}
(168,55)
 
 \put(103,39){\makebox(65,5)[l]{markiere $(v_3,v_5)$;...
 ...\line(1,-1){20}}% 
 \put(75,7){\line(1,2){10}} % 

\color {black}
 \end{picture}


\begin{picture}
(168,55)

 \put(103,33){\makebox(65,5)[l]{markiere $(v_5,v_7)$;}...
 ...ine(1,0){20}} % 4
 \put(75,7){\line(1,2){10}} % 6

\color {black}
 \end{picture}

Beobachtung: \fbox {\parbox[c]{12.45cm}{\textbf{Satz:}
Dijkstra's Algorithmus (mit Fibonacci-...
 ...das 
 Single-Source-Shortest-Path-Problem in Zeit $\mathcal{O}(m+n \log n)$.
}}


Bemerkung:
1.
Verwendet man Dijkstra's Algorithmus mit d-Heaps, so erhält man Laufzeit \fbox {$\mathcal{O}(m \log_{2+\frac{m}{n}}n)$}
2.
Mikkel Thorup (STOC '98): \fbox {$\mathcal{O}(m)$}

next up previous contents
Next: Dikstra's Algorithmus mit Radix-Heaps Up: Das single-source-shortest-path-Problem Previous: Das single-source-shortest-path-Problem
Abbas-Bardia Kabiri-Jarghouyeh
3/3/1999