KruskalsAlgorithm.tex 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. % Author: Martin Thoma
  2. \subsection{Algorithmus von Kruskal}
  3. \begin{frame}{Algorithmus von Kruskal}{Kruskal's algorithm}
  4. $E$: Menge der ausgewählten Kanten, $S$: Menge der erreichbaren Knoten.\vspace{10pt}\pause
  5. So lange, bis alle Knoten erreichbar sind:
  6. Wähle Kante mit geringstem Gewicht
  7. Wenn 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.
  8. \end{frame}
  9. \begin{frame}{Algorithmus von Kruskal}{Kruskal's algorithm}
  10. \begin{figure}
  11. \begin{tikzpicture}[scale=1.8, auto,swap]
  12. % Draw a 7,11 network
  13. % First we draw the vertices
  14. \foreach \pos/\name in {{(0,2)/a}, {(2,1)/b}, {(4,1)/c},
  15. {(0,0)/d}, {(3,0)/e}, {(2,-1)/f}, {(4,-1)/g}}
  16. \node[vertex] (\name) at \pos {$\name$};
  17. % Connect vertices with edges and draw weights
  18. \foreach \source/ \dest /\weight in {b/a/7, c/b/8,d/a/5,d/b/9,
  19. e/b/7, e/c/5,e/d/15,
  20. f/d/6,f/e/8,
  21. g/e/9,g/f/11}
  22. \path[edge] (\source) -- node[weight] {$\weight$} (\dest);
  23. % Start animating the vertex and edge selection.
  24. \foreach \vertex / \fr in {d/1,a/1,e/2,c/2,f/3,b/4,g/10}
  25. \path<\fr-> node[selected vertex] at (\vertex) {$\vertex$};
  26. % For convenience we use a background layer to highlight edges
  27. % This way we don't have to worry about the highlighting covering
  28. % weight labels.
  29. \begin{pgfonlayer}{background}
  30. \pause
  31. \foreach \source / \dest / \fr in {a/d/1,c/e/2,d/f/3,a/b/4,b/e/6,e/g/10}
  32. \path<\fr->[selected edge] (\source.center) -- (\dest.center);
  33. \foreach \source / \dest / \fr in {d/b/5,b/c/7,d/e/8,e/f/9,f/g/11}
  34. \path<\fr->[ignored edge] (\source.center) -- (\dest.center);
  35. \end{pgfonlayer}
  36. \end{tikzpicture}
  37. \end{figure}
  38. \end{frame}
  39. %% end of source
  40. \begin{frame}[fragile]
  41. \frametitle{Algorithmus von Kruskal}
  42. \begin{lstlisting}
  43. s is disjunct set of edges
  44. n is number of edges in original graph
  45. while s less than n - 1
  46. e = smallest weight edge not deleted yet
  47. // edge e = (u, v)
  48. uset = s.find(u)
  49. vset = s.find(v)
  50. if (uset != vset)
  51. edgesAccepted = edgesAccepted + 1
  52. s.unionSets(uset, vset)
  53. end if
  54. end while
  55. \end{lstlisting}
  56. \end{frame}
  57. \begin{frame}{Algorithmus von Kruskal}{Kruskal's algorithm}
  58. Erfunden von:
  59. 1956: Joseph Kruskal
  60. \begin{figure}
  61. \includegraphics[scale=0.6]{Material/kruskal.jpg}
  62. \caption{Kruskal}
  63. \end{figure}
  64. \end{frame}