Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

📚 The CoCalc Library - books, templates and other resources

132928 views
License: OTHER
1
\subsection{SCCs finden}
2
\begin{frame}{Wie findet man SCCs?}{}
3
\begin{wrapfigure}{r}{150px}
4
\begin{center}
5
\includegraphics{Material/Bob_Tarjan.jpg}
6
\end{center}
7
\caption{Robert Tarjan}
8
\end{wrapfigure}
9
Algorithmus von Robert Tarjan
10
11
% Source: http://commons.wikimedia.org/wiki/File:Bob_Tarjan.jpg
12
13
nutzt Tiefensuche im Graphen
14
\end{frame}
15
16
17
\tikzstyle StackBox=[style=help lines,color=blue!50,fill=white]
18
\tikzstyle{abstract}=[rectangle, draw=black,
19
fill=orange!40,
20
text centered, anchor=center, text=white, text width=0.4cm, text height=0.4cm]
21
\tikzstyle{textstyle}=[rectangle, draw=white,
22
fill=white, anchor=base west, text=black, text width=3cm, text height=0.4cm]
23
\tikzstyle{textstyleMini}=[rectangle, draw=white,
24
fill=white, anchor=center, text=black, text width=0.5cm, text height=0.4cm]
25
26
\begin{frame}
27
28
\begin{algorithm}[H]
29
\begin{algorithmic}
30
\Function{startTarjan}{Graph g}
31
\State $indexCounter \gets 0$
32
\State $stack$
33
\ForAll{$node$ in $g$}
34
\If{$!node.visited$}
35
\Call{tarjan}{$node$}
36
\EndIf
37
\EndFor
38
\EndFunction
39
\end{algorithmic}
40
\caption{Tarjans Algorithmus zur bestimmung starker Zusammenhangskomponenten}
41
\label{alg:seq1}
42
\end{algorithm}
43
\end{frame}
44
45
\begin{frame}
46
\begin{algorithm}[H]
47
\begin{algorithmic}
48
\Function{tarjan}{Node* node}
49
\State $node.visited \gets $ \textbf{true}
50
\State $node.index \gets indexCounter++$
51
\State $stack.push(node)$
52
\ForAll{$successor$ in $node.successors$}
53
\If{$!node.visited$}
54
\Call{tarjan}{successor}
55
\EndIf
56
\State $node.lowlink \gets$ \Call{min}{$node.lowlink, successor.lowlink$}
57
\EndFor
58
59
\boxto<1->{a}\If{$node.lowlink == node.index$}
60
\Repeat
61
\State $successor \gets stack.pop()$
62
\Until{$successor == node$}
63
\EndIf\tikzmark{a}
64
\EndFunction
65
\end{algorithmic}
66
\label{alg:seq2}
67
\end{algorithm}
68
69
% To insert the annotation
70
\begin{tikzpicture}[remember picture,overlay]
71
\coordinate (a) at ($(a)+(8.5,3)$); % <= adjust this parameter to move the position of the annotation
72
\node[rectangle,draw, gray,text width=3cm,align=left,right] at (a) {SCC wurde gefunden, ggf. ausgeben};
73
\end{tikzpicture}
74
\end{frame}
75
76
\begin{frame}{Wie findet man SCCs?}{}
77
\begin{figure}
78
\begin{tikzpicture}[->,scale=1.8, auto,swap]
79
\node[textstyle] (Text) at (0,3) {Rekursionstiefe:};
80
\node[textstyle] (RecDepth) at (3,3) {};
81
82
% Draw the vertices
83
\foreach \pos/\name in {{(0,0)/a}, {(0,2)/b}, {(1,2)/c},
84
{(1,0)/d}, {(2,1)/e}, {(3,1)/f},
85
{(4,2)/g}, {(5,2)/h}, {(4,0)/i},
86
{(5,0)/j}}
87
\node[vertex] (\name) at \pos {$\name$};
88
89
% Connect vertices with edges
90
\foreach \source/ \dest /\pos in {a/b/,b/c/,c/d/,d/a/,
91
c/e/bend left, d/e/,e/c/,
92
e/f/,
93
f/g/, f/i/,g/f/bend right,i/f/bend left,
94
g/h/, h/j/, j/i/, i/g/}
95
\path (\source) edge [\pos] node {} (\dest);
96
97
% Start animating the vertex and edge selection.
98
\foreach \vertex / \fr / \lowlink / \index in {a/1/0/0,b/2/1/1,c/3/2/2,d/4/0/3,e/5/2/4,f/6/5/5,g/7/6/6,h/8/7/7,j/9/8/8,i/10/5/9} {
99
\path<\fr-> node[selected vertex] at (\vertex) {$\vertex_{\lowlink, \index}$};
100
\path<\fr-> node[textstyleMini] at (RecDepth) {$\index$};
101
}
102
% Start animating the edge selection.
103
% For convenience we use a background layer to highlight edges
104
% This way we don't have to worry about the highlighting covering
105
% weight labels.
106
\begin{pgfonlayer}{background}
107
\path<4->[ignored edge] (d.center) edge [] node {} (a.center);
108
\path<5->[ignored edge] (e.center) edge [] node {} (c.center);
109
\path<10->[ignored edge] (i.center) edge [bend left] node {} (f.center);
110
\foreach \source / \dest / \fr / \pos in {a/b/2/,b/c/3/,c/d/4/, d/e/5/,e/f/6/,f/g/7/,g/h/8/,
111
h/j/9/,j/i/10/}
112
\path<\fr->[selected edge] (\source.center) edge [\pos] node {} (\dest.center);
113
\end{pgfonlayer}
114
% go back in recursion
115
% Start animating.
116
\foreach \vertex / \fr / \lowlink / \index in {j/11/5/8,h/12/5/7,g/13/5/6,f/14/5/5} {
117
\path<\fr-> node[selected vertex] at (\vertex) {$\vertex_{\lowlink, \index}$};
118
\path<\fr-> node[textstyleMini] at (RecDepth) {$\index$};
119
}
120
% mark first scc
121
\begin{pgfonlayer}{background}
122
\path<15->[color=blue,fill=green!20] (4.2,1) circle (1.6cm);
123
\end{pgfonlayer}
124
% go back in recursion
125
% Start animating.
126
\foreach \vertex / \fr / \lowlink / \index in {e/16/2/4,c/17/0/3,b/18/0/1,a/19/0/0} {
127
\path<\fr-> node[selected vertex] at (\vertex) {$\vertex_{\lowlink, \index}$};
128
\path<\fr-> node[textstyleMini] at (RecDepth) {$\index$};
129
}
130
% mark first scc
131
\begin{pgfonlayer}{background}
132
\path<20->[color=blue,fill=green!20] (0.6,1) circle (1.6cm);
133
\end{pgfonlayer}
134
\end{tikzpicture}
135
\end{figure}
136
\end{frame}
137
138