PrimsAlgorithm.tex 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. % Author: Kjell Magne Fauske
  2. % Source: http://www.texample.net/tikz/examples/prims-algorithm/
  3. % Declare layers
  4. \pgfdeclarelayer{background}
  5. \pgfsetlayers{background,main}
  6. \subsection{Algorithmus von Prim}
  7. \begin{frame}{Algorithmus von Prim}{Prim's algorithm}
  8. $S$ ist Menge aller erreichten Knoten, $E$ ist Menge der ausgewählten Kanten.\pause
  9. Starte bei einem beliebigen Knoten: füge zu $S$ hinzu.
  10. \begin{enumerate}
  11. \item wähle Kante am \emph{Rand} von $S$ mit dem geringsten Gewicht und füge zu $E$ hinzu. \pause
  12. \item füge zugehörigen Knoten zu $S$ hinzu.
  13. \item Fehlt ein Knoten in $S$ ? goto 1
  14. \end{enumerate}
  15. \end{frame}
  16. \begin{frame}{Algorithmus von Prim}{Prim's algorithm}
  17. %% Adjacency matrix of graph
  18. %% \ a b c d e f g
  19. %% a x 7 5
  20. %% b 7 x 8 9 7
  21. %% c 8 x 5
  22. %% d 5 9 x 15 6
  23. %% e 7 5 15 x 8 9
  24. %% f 6 8 x 11
  25. %% g 9 11 x
  26. \begin{figure}
  27. \begin{tikzpicture}[scale=1.8, auto,swap]
  28. % Draw a 7,11 network
  29. % First we draw the vertices
  30. \foreach \pos/\name in {{(0,2)/a}, {(2,1)/b}, {(4,1)/c},
  31. {(0,0)/d}, {(3,0)/e}, {(2,-1)/f}, {(4,-1)/g}}
  32. \node[vertex] (\name) at \pos {$\name$};
  33. % Connect vertices with edges and draw weights
  34. \foreach \source/ \dest /\weight in {b/a/7, c/b/8,d/a/5,d/b/9,
  35. e/b/7, e/c/5,e/d/15,
  36. f/d/6,f/e/8,
  37. g/e/9,g/f/11}
  38. \path[edge] (\source) -- node[weight] {$\weight$} (\dest);
  39. % Start animating the vertex and edge selection.
  40. \foreach \vertex / \fr in {d/1,a/2,f/3,b/4,e/5,c/6,g/7}
  41. \path<\fr-> node[selected vertex] at (\vertex) {$\vertex$};
  42. % For convenience we use a background layer to highlight edges
  43. % This way we don't have to worry about the highlighting covering
  44. % weight labels.
  45. \begin{pgfonlayer}{background}
  46. \pause
  47. \foreach \source / \dest in {d/a,d/f,a/b,b/e,e/c,e/g}
  48. \path<+->[selected edge] (\source.center) -- (\dest.center);
  49. \foreach \source / \dest / \fr in {d/b/4,d/e/5,e/f/5,b/c/6,f/g/7}
  50. \path<\fr->[ignored edge] (\source.center) -- (\dest.center);
  51. \end{pgfonlayer}
  52. \end{tikzpicture}
  53. \end{figure}
  54. \end{frame}
  55. %% end of source
  56. \begin{frame}{Algorithmus von Prim}{Prim's algorithm}
  57. %source http://inserv.math.muni.cz/biografie/obrazky/jarnik_vojtech.jpg
  58. %http://www.ams.org/featurecolumn/images/january2006/trees9.jpg
  59. \textbf{Erfinder}
  60. \begin{itemize}
  61. \item 1930: Vojtěch Jarník
  62. \item 1957: Robert C. Prim
  63. \item 1959 wiederentdeckt von Edsger Dijkstra
  64. \end{itemize}
  65. \begin{figure}
  66. \centering
  67. \mbox{\subfigure{\includegraphics[width=0.6in]{Material/jarnik_vojtech.jpg}}\quad
  68. \subfigure{\includegraphics[width=0.6in]{Material/Prim.jpg} }}
  69. \caption{Jarnik Vojtech und Prim}
  70. \end{figure}
  71. \textbf{Alternative Bezeichnungen}
  72. \begin{itemize}
  73. \item DJP algorithm
  74. \item Jarník algorithm
  75. \item Prim–Jarník algorithm
  76. \end{itemize}
  77. \end{frame}