📚 The CoCalc Library - books, templates and other resources
License: OTHER
% Author: Martin Thoma1\subsection{Algorithmus von Kruskal}2\begin{frame}{Algorithmus von Kruskal}{Kruskal's algorithm}3$E$: Menge der ausgewählten Kanten, $S$: Menge der erreichbaren Knoten.\vspace{10pt}\pause45So lange, bis alle Knoten erreichbar sind:67Wähle Kante mit geringstem Gewicht89Wenn durch ausgewählte Kante ein Knoten erreichbar ist, der davor nicht in $S$ war, füge diese Kante zu $E$ und Knoten zu $E$ hinzu.10\end{frame}111213\begin{frame}{Algorithmus von Kruskal}{Kruskal's algorithm}14\begin{figure}15\begin{tikzpicture}[scale=1.8, auto,swap]16% Draw a 7,11 network17% First we draw the vertices18\foreach \pos/\name in {{(0,2)/a}, {(2,1)/b}, {(4,1)/c},19{(0,0)/d}, {(3,0)/e}, {(2,-1)/f}, {(4,-1)/g}}20\node[vertex] (\name) at \pos {$\name$};21% Connect vertices with edges and draw weights22\foreach \source/ \dest /\weight in {b/a/7, c/b/8,d/a/5,d/b/9,23e/b/7, e/c/5,e/d/15,24f/d/6,f/e/8,25g/e/9,g/f/11}26\path[edge] (\source) -- node[weight] {$\weight$} (\dest);27% Start animating the vertex and edge selection.28\foreach \vertex / \fr in {d/1,a/1,e/2,c/2,f/3,b/4,g/10}29\path<\fr-> node[selected vertex] at (\vertex) {$\vertex$};30% For convenience we use a background layer to highlight edges31% This way we don't have to worry about the highlighting covering32% weight labels.33\begin{pgfonlayer}{background}34\pause35\foreach \source / \dest / \fr in {a/d/1,c/e/2,d/f/3,a/b/4,b/e/6,e/g/10}36\path<\fr->[selected edge] (\source.center) -- (\dest.center);37\foreach \source / \dest / \fr in {d/b/5,b/c/7,d/e/8,e/f/9,f/g/11}38\path<\fr->[ignored edge] (\source.center) -- (\dest.center);39\end{pgfonlayer}40\end{tikzpicture}41\end{figure}42\end{frame}43%% end of source4445\begin{frame}[fragile]46\frametitle{Algorithmus von Kruskal}47\begin{lstlisting}48s is disjunct set of edges49n is number of edges in original graph50while s less than n - 151e = smallest weight edge not deleted yet52// edge e = (u, v)53uset = s.find(u)54vset = s.find(v)55if (uset != vset)56edgesAccepted = edgesAccepted + 157s.unionSets(uset, vset)58end if59end while60\end{lstlisting}61\end{frame}6263\begin{frame}{Algorithmus von Kruskal}{Kruskal's algorithm}64Erfunden von:65661956: Joseph Kruskal6768\begin{figure}69\includegraphics[scale=0.6]{Material/kruskal.jpg}70\caption{Kruskal}71\end{figure}72\end{frame}737475