diff --git a/20151126/ainf-20151126.pdf b/20151126/ainf-20151126.pdf new file mode 100644 index 0000000000000000000000000000000000000000..885d870b02f78c88a30d75be72917149e0c560f4 Binary files /dev/null and b/20151126/ainf-20151126.pdf differ diff --git a/20151126/ainf-20151126.tex b/20151126/ainf-20151126.tex new file mode 100644 index 0000000000000000000000000000000000000000..036791bb9d0847fcef892f6f67dcf75191d4937f --- /dev/null +++ b/20151126/ainf-20151126.tex @@ -0,0 +1,347 @@ +% ainf-20151126.pdf - Lecture Slides on Applied Computer Sciences +% Copyright (C) 2012, 2013, 2015 Peter Gerwinski +% +% This document is free software: you can redistribute it and/or +% modify it either under the terms of the Creative Commons +% Attribution-ShareAlike 3.0 License, or under the terms of the +% GNU General Public License as published by the Free Software +% Foundation, either version 3 of the License, or (at your option) +% any later version. +% +% This document is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this document. If not, see <http://www.gnu.org/licenses/>. +% +% You should have received a copy of the Creative Commons +% Attribution-ShareAlike 3.0 Unported License along with this +% document. If not, see <http://creativecommons.org/licenses/>. + +\documentclass[10pt,t]{beamer} + +\usepackage{pgslides} +\usepackage{pdftricks} + +\newrgbcolor{orange}{0.7 0.2 0.0} + +\begin{psinputs} + \usepackage[latin1]{inputenc} + \usepackage[german]{babel} + \usepackage[T1]{fontenc} + \usepackage{helvet} + \renewcommand*\familydefault{\sfdefault} + \usepackage{pstricks,pst-grad,pst-node,pst-plot} +\end{psinputs} + +\title{Angewandte Informatik} +\author{Prof.\ Dr.\ rer.\ nat.\ Peter Gerwinski} +\date{26.\ November 2015} + +\begin{document} + +\maketitleframe + +\sectionnonumber{\inserttitle} + +\begin{frame} + + \showsectionnonumber + + \begin{itemize} + \item[\textbf{1}] \textbf{Einführung} + \item[\textbf{2}] \textbf{Einführung in C} + \item[\textbf{3}] \textbf{Bibliotheken} + \item[\textbf{4}] \textbf{Algorithmen} + \begin{itemize} + \item[4.1] Differentialgleichungen + \color{medgreen} + \item[4.2] Rekursion + \color{red} + \item[4.3] Stack und FIFO + \item[4.4] Aufwandsabschätzungen + \end{itemize} + \color{gray} + \item[\textbf{5}] \textbf{Hardwarenahe Programmierung} + \item[\makebox(0,0){\textbf{\raisebox{0.5ex}{\dots}}}] +% \item[\textbf{6}] \textbf{Ergänzungen und Ausblicke} + \end{itemize} + +\end{frame} + +\sectionnonumber{Ergänzungen} +\subsectionnonumber{OpenGL} + +\begin{frame} + + \showsectionnonumber + \showsubsectionnonumber + + \begin{itemize} + \item + \textbf{Doppelte Pufferung}\\ + 2 "`Bildschirme"': einer zum Zeichnen; einer wird angezeigt\\ + \file{opengl-magic-double.c}, \lstinline{gluSwapBuffers()} + \item + \textbf{Im Display-Handler} (\lstinline{draw()}) \textbf{wirklich nur zeichnen!}\\ + Wir haben nicht unter Kontrolle, wann, wie oft oder ob überhaupt\\ + diese Funktion aufgerufen wird. + \end{itemize} + +\end{frame} + +\subsectionnonumber{Umgang mit Bibliotheken} + +\begin{frame}[fragile] + + \showsectionnonumber + \showsubsectionnonumber + + \begin{itemize} + \item + \textbf{Separates Compilieren}\\ + \begin{lstlisting}[style=terminal,gobble=8] + $ ¡gcc -c -Wall opengl-magic.c¿ + $ ¡gcc -c -Wall textured-spheres.c¿ + $ ¡gcc -Wall orbit-x.c -lGL -lGLU -lglut \ + opengl-magic.o textured-spheres.o -o orbit-x¿ + \end{lstlisting} + \item + Die \textbf{Link-Reihenfolge} kann eine Rolle spielen!\\ + \begin{lstlisting}[style=terminal,gobble=8] + $ ¡gcc -Wall orbit-x.c \ + opengl-magic.o textured-spheres.o \ + -lGL -lGLU -lglut -o orbit-x¿ + \end{lstlisting} + Notfalls: + \begin{lstlisting}[style=terminal,gobble=8] + $ ¡gcc -Wall orbit-x.c -lGL -lGLU -lglut \ + opengl-magic.o textured-spheres.o \ + -lGL -lGLU -lglut -o orbit-x¿ + \end{lstlisting} + \end{itemize} + +\end{frame} + +\subsectionnonumber{Parameter des Hauptprogramms} + +\begin{frame}[fragile] + \showsectionnonumber + \showsubsectionnonumber + + \medskip + + \begin{lstlisting} + #include <stdio.h> + + int main (int argc, char **argv) + { + printf ("argc = %d\n", argc); + for (int i = 0; i < argc; i++) + printf ("argv[%d] = \"%s\"\n", i, argv[i]); + return 0; + } + \end{lstlisting} + +\end{frame} + +\section{Einführung} +\section{Einführung in C} +\section{Bibliotheken} + +\section{Algorithmen} +\subsection{Differentialgleichungen} +\subsection{Rekursion} +\subsection{Stack und FIFO} + +\begin{frame}[fragile] + + \showsubsection + + \bigskip + + \begin{minipage}[b]{6cm} + \begin{center} + "`First In -- First Out"' + + \bigskip + + \begin{picture}(6,4) + \thicklines + \color{structure} + \put(0.5,0){\line(1,0){5}} + + \put(3.5,0){\only<1-5>{\line(0,1){1}}} + \put(4.5,0){\only<1-4>{\line(0,1){1}}} + \put(3.5,1){\only<1-4>{\line(1,0){1}}} + \put(4.0,0.5){\only<1-4>{\makebox(0,0){\lstinline{3}}}} + \put(3.0,1.5){\only<1>{\vector(1,-1){0.45}}} + \put(3.0,1.5){\only<1>{\makebox(0,0)[b]{\lstinline{push (3)}}}} + + \put(2.5,0){\only<2-6>{\line(0,1){1}}} + \put(2.5,1){\only<2-5>{\line(1,0){1}}} + \put(3.0,0.5){\only<2-5>{\makebox(0,0){\lstinline{7}}}} + \put(2.0,1.5){\only<2>{\vector(1,-1){0.45}}} + \put(2.0,1.5){\only<2>{\makebox(0,0)[b]{\lstinline{push (7)}}}} + + \put(1.5,0){\only<3-6>{\line(0,1){1}}} + \put(1.5,1){\only<3-6>{\line(1,0){1}}} + \put(2.0,0.5){\only<3-6>{\makebox(0,0){\lstinline{137}}}} + \put(1.0,1.5){\only<3>{\vector(1,-1){0.45}}} + \put(1.0,1.5){\only<3>{\makebox(0,0)[b]{\lstinline{push (137)}}}} + + \put(4.55,1.05){\only<4>{\vector(1,1){0.45}}} + \put(5.00,1.60){\only<4>{\makebox(0,0)[b]{\lstinline{pop ()}: 3}}} + + \put(3.55,1.05){\only<5>{\vector(1,1){0.45}}} + \put(4.00,1.60){\only<5>{\makebox(0,0)[b]{\lstinline{pop ()}: 7}}} + + \put(2.55,1.05){\only<6>{\vector(1,1){0.45}}} + \put(3.00,1.60){\only<6>{\makebox(0,0)[b]{\lstinline{pop ()}: 137}}} + \end{picture} + + \bigskip + + FIFO = Queue = Reihe + \end{center} + \end{minipage}\hfill + \begin{minipage}[b]{6cm} + \begin{center} + "`Last In -- First Out"' + + \bigskip + + \begin{picture}(6,4) + \thicklines + \color{structure} + \put(1.5,0){\line(1,0){3}} + + \put(2.5,0){\line(0,1){1}} + \put(3.5,0){\line(0,1){1}} + \put(2.5,1){\line(1,0){1}} + \put(3.0,0.5){\makebox(0,0){\lstinline{3}}} + \put(2.0,1.5){\only<1>{\vector(1,-1){0.45}}} + \put(2.0,1.5){\only<1>{\makebox(0,0)[b]{\lstinline{push (3)}}}} + + \put(2.5,1){\only<2-5>{\line(0,1){1}}} + \put(3.5,1){\only<2-5>{\line(0,1){1}}} + \put(2.5,2){\only<2-5>{\line(1,0){1}}} + \put(3.0,1.5){\only<2-5>{\makebox(0,0){\lstinline{7}}}} + \put(2.0,2.5){\only<2>{\vector(1,-1){0.45}}} + \put(2.0,2.5){\only<2>{\makebox(0,0)[b]{\lstinline{push (7)}}}} + + \put(2.5,2){\only<3-4>{\line(0,1){1}}} + \put(3.5,2){\only<3-4>{\line(0,1){1}}} + \put(2.5,3){\only<3-4>{\line(1,0){1}}} + \put(3.0,2.5){\only<3-4>{\makebox(0,0){\lstinline{137}}}} + \put(2.0,3.5){\only<3>{\vector(1,-1){0.45}}} + \put(2.0,3.5){\only<3>{\makebox(0,0)[b]{\lstinline{push (137)}}}} + + \put(3.55,3.05){\only<4>{\vector(1,1){0.45}}} + \put(4.00,3.60){\only<4>{\makebox(0,0)[b]{\lstinline{pop ()}: 137}}} + + \put(3.55,2.05){\only<5>{\vector(1,1){0.45}}} + \put(4.00,2.60){\only<5>{\makebox(0,0)[b]{\lstinline{pop ()}: 7}}} + + \put(3.55,1.05){\only<6>{\vector(1,1){0.45}}} + \put(4.00,1.60){\only<6>{\makebox(0,0)[b]{\lstinline{pop ()}: 3}}} + \end{picture} + + \bigskip + + LIFO = Stack = Stapel + \end{center} + \end{minipage} + +% +% \dots + +\end{frame} + +\subsection{Aufwandsabschätzungen} + +\begin{frame}[fragile] + + \showsubsection + + Beispiel: Sortieralgorithmen + + \begin{itemize} + \item + Maximum suchen\only<2->{: $\mathcal{O}(n)$} + \hfill + \begin{minipage}[t]{5.6cm} + \vspace*{-1.3cm} + \begin{pdfpic} + \psset{unit=0.5pt} + \begin{pspicture}(-20,-20)(250,200) + \psline[arrows=->](-10,0)(200,0) + \psline[arrows=->](0,-10)(0,200) + \psplot[plotpoints=200]{1}{125}{2 x 0.06 mul exp} + \put(70,190){\mbox{$g(n) \sim 2^n$}} + \psplot[plotpoints=200]{0}{190}{x x mul 0.005 mul} + \put(190,190){\mbox{$g(n) \sim n^2$}} + \psplot[plotpoints=200]{1}{190}{x ln x mul 0.1 mul} + \put(195,100){\mbox{$g(n) \sim n \log n$}} + \psplot[plotpoints=200]{0}{190}{x 0.4 mul} + \put(195,75){\mbox{$g(n) \sim n$}} + \psplot[plotpoints=200]{1}{190}{x ln 10 mul} + \put(195,50){\mbox{$g(n) \sim \log n$}} + \put(205,0){\makebox(0,0)[l]{$n$}} + \put(-10,210){\makebox(0,0)[l]{$g(n)$}} + \psplot[plotpoints=200]{1}{190}{30} + \put(195,25){\mbox{$g(n) \sim 1$}} + \end{pspicture} + \end{pdfpic} + \small + \begin{description}\itemsep0pt + \item[$n$:] Eingabedaten + \item[$g(n)$:] Rechenzeit + \end{description} + \vspace*{-10cm}\strut + \end{minipage} + \pause[3] + \item + Maximum ans Ende tauschen\\ + \textarrow\ Selectionsort\pause: $\mathcal{O}(n^2)$ + \pause + \item + Während Maximumsuche prüfen,\\abbrechen, falls schon sortiert\\ + \textarrow\ Bubblesort\pause: $\mathcal{O}(n)$ bis $\mathcal{O}(n^2)$ + \pause + \item + Rekursiv sortieren\\ + \textarrow\ Quicksort\pause: $\mathcal{O}(n\log n)$ bis $\mathcal{O}(n^2)$\hfill + \end{itemize} + +\end{frame} + +\sectionnonumber{\inserttitle} + +\begin{frame} + + \showsectionnonumber + + \begin{itemize} + \item[\textbf{1}] \textbf{Einführung} + \item[\textbf{2}] \textbf{Einführung in C} + \item[\textbf{3}] \textbf{Bibliotheken} + \item[\textbf{4}] \textbf{Algorithmen} + \begin{itemize} + \item[4.1] Differentialgleichungen + \item[4.2] Rekursion + \color{medgreen} + \item[4.3] Stack und FIFO + \item[4.4] Aufwandsabschätzungen + \end{itemize} + \item[\textbf{5}] \textbf{Hardwarenahe Programmierung} + \color{gray} + \item[\makebox(0,0){\textbf{\raisebox{0.5ex}{\dots}}}] +% \item[\textbf{6}] \textbf{Ergänzungen und Ausblicke} + \end{itemize} + +\end{frame} + +\end{document} diff --git a/20151126/ainf-uebung-20151126.pdf b/20151126/ainf-uebung-20151126.pdf new file mode 100644 index 0000000000000000000000000000000000000000..65f4dd206fc8fc441c13a0e2ec866112dda13e7f Binary files /dev/null and b/20151126/ainf-uebung-20151126.pdf differ diff --git a/20151126/ainf-uebung-20151126.tex b/20151126/ainf-uebung-20151126.tex new file mode 100644 index 0000000000000000000000000000000000000000..39e16cc7c86c4acc56fd63b4b483123cecfa407b --- /dev/null +++ b/20151126/ainf-uebung-20151126.tex @@ -0,0 +1,132 @@ +% ainf-uebung-20151126.pdf - Exercises on Applied Computer Sciences +% Copyright (C) 2013, 2015 Peter Gerwinski +% +% This document is free software: you can redistribute it and/or +% modify it either under the terms of the Creative Commons +% Attribution-ShareAlike 3.0 License, or under the terms of the +% GNU General Public License as published by the Free Software +% Foundation, either version 3 of the License, or (at your option) +% any later version. +% +% This document is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this document. If not, see <http://www.gnu.org/licenses/>. +% +% You should have received a copy of the Creative Commons +% Attribution-ShareAlike 3.0 Unported License along with this +% document. If not, see <http://creativecommons.org/licenses/>. + +\documentclass[a4paper]{article} + +\usepackage{pgscript} +\usepackage{enumerate} + +\newcounter{exercise} +\newcommand{\exercise}[1]{\addtocounter{exercise}{1}\subsection*{Aufgabe \arabic{exercise}: #1}} + +\newcounter{points} +\newcommand{\onepoint}{(1 Punkt)\addtocounter{points}{1}} +\newcommand{\points}[1]{(#1 Punkte)\addtocounter{points}{#1}} + +\begin{document} + + \thispagestyle{empty} + + \section*{Angewandte Informatik\\Übungsaufgaben -- 26.\ November 2015} + + \exercise{Koordinaten-FIFO} + + Implementieren Sie einen FIFO für Koordinaten-Paare.\\ + Koordinatenpaare sollen "`hintereinander eingereiht"' werden. + + \begin{itemize} + \item + Eine Funktion \lstinline{push (int x, int y)} + schiebt sie in den FIFO. + \item + Eine Funktion \lstinline{pop (int &x, int &y)} + liest und entfernt sie wieder aus dem FIFO. + \item + Eine Funktion \lstinline{dump ()} + gibt den Inhalt des FIFO auf dem Bildschirm aus. + \end{itemize} + \points{10} + + \exercise{Arrays mit Zahlen} + + \begin{minipage}[t]{0.5\textwidth} + Wir betrachten das folgende Programm: + \begin{lstlisting}[gobble=6] + #include <stdio.h> + + void f (int *s0, int *s1) + { + while (*s0 >= 0) + { + int *s = s1; + while (*s >= 0) + if (*s0 == *s++) + printf ("%d ", *s0); + s0++; + } + printf ("\n"); + } + + int main (void) + { + int a[] = { 10, 4, 3, 7, 12, 0, 1, -1 }; + int b[] = { 7, 14, 0, 8, 9, 22, 10, -1 }; + f (a, b); + return 0; + } + \end{lstlisting} + \end{minipage}\hfill + \begin{minipage}[t]{0.5\textwidth} + \vspace*{-\bigskipamount} + \begin{enumerate}[\quad(a)] + \item + Was bewirkt die Funktion \lstinline{f} und warum?\\ + \points{4} + \item + Von welcher Ordnung (Landau-Symbol) ist die Funktion und warum? + + Wir beziehen uns hierbei auf die Anzahl der Vergleiche + in Abhängigkeit von der Länge der Eingabedaten \lstinline{s0} und \lstinline{s1}. + Für die Rechnung dürfen Sie beide Längen mit $n$ gleichsetzen, + obwohl sie normalerweise nicht gleich sind. + \points{2} + \item + Was passiert, wenn Sie beim Aufruf der Funktion für einen der + Parameter den Wert \lstinline{NULL} übergeben und warum? + \points{2} + \item + Was passiert, wenn Sie das Hauptprogramm wie folgt abändern + (\file{aufgabe-1d.c}) und warum? + \begin{lstlisting}[gobble=8] + int main (void) + { + int a[] = { 10, 4, 3, 7, 12, 0, 1 }; + int b[] = { 7, 14, 0, 8, 9, 22, 10 }; + f (a, b); + return 0; + } + \end{lstlisting} + \points{2} + \item + Beschreiben Sie -- in Worten und/oder als C-Quelltext --, wie + sich die Funktion \lstinline{f} effizienter gestalten läßt, + wenn man die ihr übergebenen Arrays \lstinline{s0} und + \lstinline{s1} als sortiert voraussetzt.\\ + \points{5} + \item + Von welcher + Ordnung (Landau-Symbol) ist Ihre effizientere Version der Funktion und warum?\\ + \points{2} + \end{enumerate} + \end{minipage} + +\end{document} diff --git a/20151126/logo-hochschule-bochum-cvh-text.pdf b/20151126/logo-hochschule-bochum-cvh-text.pdf new file mode 120000 index 0000000000000000000000000000000000000000..a05946126bc0ce6a2818740da2893f59eb0c659c --- /dev/null +++ b/20151126/logo-hochschule-bochum-cvh-text.pdf @@ -0,0 +1 @@ +../common/logo-hochschule-bochum-cvh-text.pdf \ No newline at end of file diff --git a/20151126/logo-hochschule-bochum.pdf b/20151126/logo-hochschule-bochum.pdf new file mode 120000 index 0000000000000000000000000000000000000000..b6b9491e370e499c9276918182cdb82cb311bcd1 --- /dev/null +++ b/20151126/logo-hochschule-bochum.pdf @@ -0,0 +1 @@ +../common/logo-hochschule-bochum.pdf \ No newline at end of file diff --git a/20151126/pgscript.sty b/20151126/pgscript.sty new file mode 120000 index 0000000000000000000000000000000000000000..95c888478c99ea7fda0fd11ccf669ae91be7178b --- /dev/null +++ b/20151126/pgscript.sty @@ -0,0 +1 @@ +../common/pgscript.sty \ No newline at end of file diff --git a/20151126/pgslides.sty b/20151126/pgslides.sty new file mode 120000 index 0000000000000000000000000000000000000000..5be1416f4216f076aa268901f52a15d775e43f64 --- /dev/null +++ b/20151126/pgslides.sty @@ -0,0 +1 @@ +../common/pgslides.sty \ No newline at end of file