Für Vorlesungen, bitte die Webseite verwenden. https://flavigny.de/lecture
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

253 lines
6.6KB

  1. \documentclass[uebung]{../../../lecture}
  2. \usepackage{listings}
  3. \usetikzlibrary{positioning}
  4. \title{Übungsblatt 6}
  5. \author{Samuel Weidemaier, Christian Merten}
  6. \usepackage{xcolor}
  7. \lstdefinestyle{mystyle}{
  8. commentstyle=\color{gray},
  9. keywordstyle=\color{blue},
  10. numberstyle=\tiny\color{gray},
  11. stringstyle=\color{black},
  12. basicstyle=\ttfamily\footnotesize,
  13. breakatwhitespace=false,
  14. breaklines=true,
  15. captionpos=b,
  16. keepspaces=true,
  17. numbers=left,
  18. numbersep=5pt,
  19. showspaces=false,
  20. showstringspaces=false,
  21. showtabs=false,
  22. tabsize=2
  23. }
  24. \lstset{style=mystyle}
  25. \usepackage{tikz, wasysym}
  26. \usetikzlibrary{automata, positioning, arrows,shapes,shadows}
  27. \tikzstyle{abstract}=[rectangle, draw=black,
  28. %text centered,
  29. anchor=north, text=black, text width=15cm, rounded corners]
  30. \tikzstyle{subgroup}=[rectangle, draw=blue,
  31. %text centered,
  32. anchor=north, text=black, text width=3.5cm, rounded corners]
  33. \tikzstyle{myarrow}=[->, >=stealth, thick]
  34. \tikzstyle{gestrichen}=[->, >=stealth, dashed]
  35. \begin{document}
  36. \punkte
  37. \begin{aufgabe}
  38. \vspace{5mm}
  39. Marker 1:
  40. \vspace{-3mm}
  41. \begin{center}
  42. \begin{tikzpicture}[shorten >= 1pt, node distance=2.5cm, on grid, auto]
  43. \node[abstract, rectangle split, rectangle split parts=2] (global) {
  44. Globale Umgebung
  45. \nodepart{second}$g$ int $1$
  46. };
  47. \node[subgroup, rectangle split, rectangle split parts=2, below left of=global, xshift=-3.3cm, yshift=-0.3cm] (main) {
  48. main() \\
  49. \nodepart{second}
  50. $a$ int $2$ \\
  51. $b$ int $14$
  52. };
  53. \node[subgroup, rectangle split, rectangle split parts=2, below right of=main, yshift=-0.4cm] (block1) {
  54. Block $1$ in main() \\
  55. \nodepart{second}
  56. $a$ int $7$ \\
  57. $g$ int $?$
  58. };
  59. \node[subgroup, rectangle split, rectangle split parts=2, right of=block1, , xshift=2.1cm, yshift=-0.32cm] (ggTab) {
  60. ggT(b, a) \\
  61. \nodepart{second}
  62. $a$ int $14$ \\
  63. $b$ int $7$ \\
  64. Null int $0$
  65. };
  66. \node[subgroup, rectangle split, rectangle split parts=2, below right of=ggTab, yshift=-0.7cm] (amodb) {
  67. $a \text{ mod } b(a,b)$ \\
  68. \nodepart{second}
  69. $a$ int $14$ \\
  70. $b$ int $7$ \\
  71. $m$ int $0$
  72. };
  73. \draw[myarrow] (main.west) -- ++(0,0) -| ([xshift=-7.2cm] global.south);
  74. \draw[myarrow] (block1.west) -- ++(0,0) -| ([xshift=-1cm] main.south);
  75. \draw[gestrichen] ([xshift=-1.4cm] ggTab.south) -- ++(0,-0.4) -| (block1.south);
  76. \draw[myarrow] (ggTab.west) -- ++(0,0) -| ([xshift=-1cm] global.south);
  77. \draw[gestrichen] (amodb.west) -- ++(0,0) -| ([xshift=-1.7cm] ggTab);
  78. \draw[myarrow] ([xshift=1cm] amodb.north) -- ++(0,0) -| ([xshift=4.1cm] global.south);
  79. \end{tikzpicture}
  80. \vspace{-10mm}
  81. \end{center}
  82. \nopagebreak
  83. Marker 2:
  84. \vspace{-2mm}
  85. \begin{center}
  86. \begin{tikzpicture}[shorten >= 1pt, node distance=2.5cm, on grid, auto]
  87. \node[abstract, rectangle split, rectangle split parts=2] (global) {
  88. Globale Umgebung
  89. \nodepart{second}$g$ int $2$
  90. };
  91. \node[subgroup, rectangle split, rectangle split parts=2, below left of=global, xshift=-3.3cm, yshift=-0.3cm] (main) {
  92. main() \\
  93. \nodepart{second}
  94. $a$ int $2$ \\
  95. $b$ int $14$
  96. };
  97. \node[subgroup, rectangle split, rectangle split parts=2, below right of=main, yshift=-0.4cm] (block1) {
  98. Block $1$ in main() \\
  99. \nodepart{second}
  100. $a$ int $7$ \\
  101. $g$ int $?$
  102. };
  103. \node[subgroup, rectangle split, rectangle split parts=2, right of=block1, , xshift=2.1cm, yshift=-0.32cm] (ggTab) {
  104. ggT(b, a) \\
  105. \nodepart{second}
  106. $a$ int $14$ \\
  107. $b$ int $7$ \\
  108. Null int $0$
  109. };
  110. \node[subgroup, rectangle split, rectangle split parts=2, below right of=ggTab, , xshift=1cm, yshift=-0.7cm] (ggTmod) {
  111. $ggT(b, a \text{ mod }b(a,b))$ \\
  112. \nodepart{second}
  113. $a$ int $7$ \\
  114. $b$ int $0$ \\
  115. Null int $0$
  116. };
  117. \draw[myarrow] (main.west) -- ++(0,0) -| ([xshift=-7.2cm] global.south);
  118. \draw[myarrow] (block1.west) -- ++(0,0) -| ([xshift=-1cm] main.south);
  119. \draw[gestrichen] ([xshift=-1.4cm] ggTab.south) -- ++(0,-0.4) -| (block1.south);
  120. \draw[myarrow] (ggTab.west) -- ++(0,0) -| ([xshift=-1cm] global.south);
  121. \draw[gestrichen] (ggTmod.west) -- ++(0,0) -| (ggTab.south);
  122. \draw[myarrow] (ggTmod.north) -- ++(0,0) -| ([xshift=4.1cm] global.south);
  123. \end{tikzpicture}
  124. \end{center}
  125. Marker 3:
  126. \begin{center}
  127. \begin{tikzpicture}[shorten >= 1pt, node distance=2.5cm, on grid, auto]
  128. \node[abstract, rectangle split, rectangle split parts=2] (global) {
  129. Globale Umgebung
  130. \nodepart{second}$g$ int $2$
  131. };
  132. \node[subgroup, rectangle split, rectangle split parts=2, below left of=global, xshift=-3.3cm, yshift=-0.3cm] (main) {
  133. main() \\
  134. \nodepart{second}
  135. $a$ int $2$ \\
  136. $b$ int $7$
  137. };
  138. \draw[myarrow] (main.west) -- ++(0,0) -| ([xshift=-7.2cm] global.south);
  139. \end{tikzpicture}
  140. \end{center}
  141. \end{aufgabe}
  142. \newpage
  143. \begin{aufgabe} Primfaktorzerlegung
  144. \begin{lstlisting}[language=C++, title=Primfaktorzerlegung, captionpos=b]
  145. #include "cpp_headers/fcpp.hh"
  146. int main() {
  147. int n = enter_int("Please enter a natural number: ");
  148. // search smallest factor, start with smallest possible: 2
  149. int k=2;
  150. // go until sqrt(n)
  151. while (k <= sqrt(n)) {
  152. // k is factor of n
  153. if (n % k == 0) {
  154. // print out the factor k
  155. print(k);
  156. // reset n to the quotient
  157. n = n / k;
  158. // restart at k=2
  159. k = 2;
  160. } else {
  161. // if k is not a factor, check next one
  162. k++;
  163. }
  164. }
  165. // n is the last prime factor of the original input number
  166. print(n);
  167. }
  168. \end{lstlisting}
  169. Die algorithmische Komplexität des Programms für $n$ Primzahl ist $\sqrt{n}$, da die Schleife
  170. für Primzahlen bis $\sqrt{n} $ durchlaufen wird.
  171. \end{aufgabe}
  172. \begin{aufgabe}
  173. siehe \textit{taschenrechner.cpp}
  174. \end{aufgabe}
  175. \end{document}