next up previous contents
Next: DFS-Algorithmus Up: Traversierung von Graphen Previous: Traversierung von Graphen

DFS-Algorithmus


while $\exists$ unvisitet v do r:= pick(random) unvisited node; push r onto stack; while stack $\neq \emptyset$ do v:= pop the top element; if not visited v then mark v visited; push all neigbour's of v onto stack; DFS_Ops(v); fi od od

Beispiel für DFS:


\begin{picture}
(70,70)
 

\color {blue}
 

\thicklines 
 
 \put(35.2,65.1){\lin...
 ...
 \put(45,5) {\line(1,1){20}} %5 

 \put(65,25){\line(-2,1){20}} %6\end{picture}

Die markierten Kanten bilden einen Spannbaum:


\begin{picture}
(60,80)
 

\color {black}
 
\qbezier(25,5)(15,5)(15,35)
\qbezier...
 ...{\circle*{2}}
 \put(15,75){\circle*{2}}

% \put(,){\makebox(5,3.5)}\end{picture}

Wir betrachten nun den Stackzustand: Im Zustand g) sind die Elemente 2, 3 und 5 als visited markiert (siehe Zustände b), c) und e)). Deswegen werden sie aus dem Stack entfernt und so wird das Element 8 zum obersten Stackelement. Im Zustand j) sind alle Elemente markiert, so daß eins nach dem anderen aus dem Stack entfernt werden.
\includegraphics {eps/3_ws99_6.eps}


Abbas-Bardia Kabiri-Jarghouyeh
3/3/1999