Skip to content
Snippets Groups Projects
Commit 399dabac authored by Peter Gerwinski's avatar Peter Gerwinski
Browse files

Vorbereitung 9.4.2018

parents
No related branches found
No related tags found
No related merge requests found
Showing
with 607 additions and 0 deletions
File added
% ad-20180409.pdf - Lecture Slides on Algorithms and Data Structures in C/C++
% Copyright (C) 2018 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/>.
% README: Einführung
\documentclass[10pt,t]{beamer}
\usepackage{pgslides}
\title{Algorithmen und Datenstrukturen in C/C++}
\author{Prof.\ Dr.\ rer.\ nat.\ Peter Gerwinski}
\date{9.\ April 2018}
\begin{document}
\maketitleframe
\nosectionnonumber{Hardwarenahe Programmierung}
\begin{frame}
\shownosectionnonumber
\begin{itemize}
\item[\textbf{1}] \textbf{Einführung}
\hfill\makebox(0,0)[br]{\raisebox{2.25ex}{\url{https://gitlab.cvh-server.de/pgerwinski/hp.git}}}
\item[\textbf{2}] \textbf{Einführung in C}
\item[\textbf{3}] \textbf{Bibliotheken}
\item[\textbf{4}] \textbf{Hardwarenahe Programmierung}
\item[\textbf{5}] \textbf{\color{black}Algorithmen}
\begin{itemize}
\color{medgreen}
\item[5.1] Differentialgleichungen
\item[5.2] Rekursion
\item[5.3] Aufwandsabschätzungen
\end{itemize}
\item[\textbf{6}] \textbf{Objektorientierte Programmierung}
\item[\textbf{7}] \textbf{\color{black}Datenstrukturen}
\begin{itemize}
\color{medgreen}
\item[7.1] Stack und FIFO
\item[7.2] Verkettete Listen
\item[7.3] Bäume
\end{itemize}
\end{itemize}
\vspace*{-1cm}
\end{frame}
\begin{frame}
\shownosectionnonumber
\begin{itemize}
\color{gray}
\item[\textbf{1}] \textbf{Einführung}
\hfill\makebox(0,0)[br]{\raisebox{2.25ex}{\url{https://gitlab.cvh-server.de/pgerwinski/hp.git}}}
\item[\textbf{2}] \textbf{Einführung in C}
\item[\textbf{3}] \textbf{Bibliotheken}
\item[\textbf{4}] \textbf{Hardwarenahe Programmierung}
\item[\textbf{5}] \textbf{\color{black}Algorithmen}
\begin{itemize}
\color{medgreen}
\item[5.1] Differentialgleichungen
\item[5.2] Rekursion
\item[5.3] Aufwandsabschätzungen
\end{itemize}
\item[\textbf{6}] \textbf{Objektorientierte Programmierung}
\item[\textbf{7}] \textbf{\color{black}Datenstrukturen}
\begin{itemize}
\color{medgreen}
\item[7.1] Stack und FIFO
\item[7.2] Verkettete Listen
\item[7.3] Bäume
\end{itemize}
\end{itemize}
\vspace*{-1cm}
\end{frame}
\nosectionnonumber{Algorithmen}
\begin{frame}
\shownosectionnonumber
{\color{medgreen}\textbf{Differentialgleichungen}}
\begin{itemize}
\item Pendel
\item Basketball
\end{itemize}
{\color{medgreen}\textbf{Rekursion}}
\begin{itemize}
\item Türme von Hanoi
\end{itemize}
\smallskip
\textarrow\ \emph{Wie rechnet man das überhaupt aus?}
\bigskip
{\color{medgreen}\textbf{Aufwandsabschätzungen}}
\begin{itemize}
\item Selectionsort
\item Bubblesort
\item Quicksort
\end{itemize}
\smallskip
\textarrow\ \emph{Wie rechnet man das möglichst effizient aus?}
\begin{itemize}
\item[\textbf{?}] möglichst schnell
\item[\textbf{?}] mit möglichst wenig Speicherplatzverbrauch
\item[\textbf{?}] unter Berücksichtigung gegebener Randbedingungen
\end{itemize}
\end{frame}
\nosectionnonumber{Datenstrukturen}
\begin{frame}
\shownosectionnonumber
\begin{visibleenv}<2->
\textbf{Structs und Objekte}
\begin{itemize}
\item zusammengehörige Daten gemeinsam speichern
\end{itemize}
\end{visibleenv}
{\color{medgreen}\textbf{Stack und FIFO}}\only<2->{\textbf{ -- Arrays}}
\begin{itemize}
\item effizientes Anfügen und Entfernen vorne und hinten
\item effizienter direkter Zugriff auf Elemente in der Mitte
\item ineffizientes Einfügen und Entfernen in der Mitte
\end{itemize}
{\color{medgreen}\textbf{Verkettete Listen}}
\begin{itemize}
\item effizientes Einfügen und Entfernen in der Mitte
\item ineffizienter direkter Zugriff auf Elemente in der Mitte
\end{itemize}
{\color{medgreen}\textbf{Bäume}}
\begin{itemize}
\item Kompromiß
\end{itemize}
\smallskip
\textarrow\ \emph{Wie speichert man das möglichst effizient?}
\begin{itemize}
\item[\textbf{?}] möglichst schnell
\item[\textbf{?}] mit möglichst wenig Speicherplatzverbrauch
\item[\textbf{?}] unter Berücksichtigung gegebener Randbedingungen
\end{itemize}
\end{frame}
\nosectionnonumber{Aufwandsabschätzungen}
\begin{frame}[fragile]
\newcommand{\w}{\hspace*{0.75pt}}
\shownosectionnonumber
\begin{picture}(0,0)
\put(7.6,-0.3){%
\begin{minipage}[t]{5.3cm}
% \vspace*{-1.0cm}\includegraphics{landau-symbols.pdf}
\vspace*{-1.0cm}\alt<3->{\includegraphics{landau-symbols-2.pdf}}%
{\includegraphics{landau-symbols.pdf}}
\small
\begin{description}\itemsep0pt\leftskip-0.5cm
\item[$n$:] Eingabedaten
\item[$g(n)$:] Rechenzeit
\end{description}
\end{minipage}}
\end{picture}
\vspace*{-1.5\bigskipamount}
\begin{itemize}
\item
Türme von Hanoi: $\mathcal{O}(2^n)$
\begin{onlyenv}<1>
\par\medskip
Für jede zusätzliche Scheibe\\verdoppelt sich die Rechenzeit!
% 32.712 * 2^32 / 3600 / 24 / 365.25 = 4452.08032888280477602859
\begin{itemize}
\arrowitem
$\frac{32,712\,\text{s}\,\cdot\,2^{32}}{3600\,\cdot\,24\,\cdot\,365,25} \approx 4452$
Jahre\\[\smallskipamount]
für 64 Scheiben
\end{itemize}
\end{onlyenv}
% \end{itemize}
%
\pause
%
% Beispiel: Sortieralgorithmen
%
% \begin{itemize}
\item
Minimum suchen: \alt<1->{$\mathcal{O}(n)$}{$\mathcal{O}(\textbf{\color{red}?})$}
% \pause
\item
\dots\ mit Schummeln: $\mathcal{O}(1)$
% \pause
% \pause
\begin{picture}(0,0)
\put(-4.742,-4.3){\begin{minipage}[t]{12cm}
Faustregel:\\Schachtelung der Schleifen zählen\\
$x$ Schleifen \textarrow\ $\mathcal{O}(n\w^x)$
\vspace{0.5\smallskipamount}
\begin{onlyenv}<3->
\begin{tabbing}
Verschlüsselung brechen (Primfaktorzerlegung):~\=\kill
\textbf{\color{red}RSA}: Schlüsselerzeugung (Berechnung von $d\/$):
\> \color{red}$\mathcal{O}\bigl((\log n)^2\bigr)$,\\[0.5\smallskipamount]
Ver- und Entschlüsselung (Exponentiation):
\> \color{red}$\mathcal{O}\kern0.5pt(n\log n)$,\\[0.5\smallskipamount]
Verschlüsselung brechen (Primfaktorzerlegung):
\> \color{red}$\mathcal{O}\bigl(2^{\sqrt{\log n\,\cdot\,\log\log n}}\bigr)$
\end{tabbing}
\end{onlyenv}
\end{minipage}}
\end{picture}
% \pause
\item
Minimum an den Anfang tauschen,\\
nächstes Minimum suchen:\\
\textarrow\ Selectionsort: $\mathcal{O}(n\w^2)$
% \pause
\item
Während Minimumsuche prüfen\\und abbrechen, falls schon sortiert\\
\textarrow\ Bubblesort: $\mathcal{O}(n)$ bis $\mathcal{O}(n\w^2)$
% \pause
\item
Rekursiv sortieren\\
\textarrow\ Quicksort: $\mathcal{O}(n\log n)$ bis $\mathcal{O}(n\w^2)$\hfill
\end{itemize}
\end{frame}
\nosectionnonumber{\inserttitle}
\begin{frame}
\shownosectionnonumber
\begin{itemize}
\item[\textbf{1}] \textbf{Einführung}
\hfill\makebox(0,0)[br]{\raisebox{2.25ex}{\url{https://gitlab.cvh-server.de/pgerwinski/ad.git}}}
\item[\textbf{2}] \textbf{\dots}
\end{itemize}
\begin{picture}(0,0)(-2,-0.5)
\put(0.5,-1.0){\mbox{\Large$\mathcal{O}(n\log n)$}}
\put(0.6,-2.7){\mbox{\large\bf B-Baum}}
\put(-1.3,-3.4){\mbox{\small\it verkettete Liste}}
\put(1.5,-4.0){\mbox{\large Datenbanken}}
\put(-1.0,-1.9){\mbox{\large\tt struct}}
\put(3.0,-2.0){\mbox{\large Wegfindung}}
\put(4.0,-3.0){\mbox{Verschlüsseln}}
\put(5.7,-4.2){\mbox{\it Datenkompression}}
\put(6.0,-1.5){\mbox{CORDIC}}
\put(8.5,-2.0){\mbox{\small\bf FFT}}
\put(7.5,-2.9){\mbox{\small\tt pointer}}
\put(3.5,-0.5){\mbox{\it Rasterung}}
\put(7.7,-0.7){\mbox{\tt array}}
\put(-0.5,-5.0){\mbox{digitale Signatur}}
\put(3.5,-5.2){\mbox{\large Hash-Tabelle}}
\put(0.0,-6.3){\mbox{\small\bf kryptographische Hash-Funktion}}
\put(6.5,-6.0){\mbox{\it Prüfsumme}}
\end{picture}
\end{frame}
\begin{frame}
\shownosectionnonumber
\begin{itemize}
\item[\textbf{1}] \textbf{Einführung}
\hfill\makebox(0,0)[br]{\raisebox{2.25ex}{\url{https://gitlab.cvh-server.de/pgerwinski/ad.git}}}
\item[\textbf{2}] \textbf{Datenorganisation}
\item[\textbf{3}] \textbf{Wegfindung}
\item[\textbf{4}] \textbf{Hardwarenahe Algorithmen}
\item[\textbf{5}] \textbf{Datenkodierung}
\color{gray}
\item[\textbf{6}] \textbf{Numerik}
\end{itemize}
\end{frame}
\nosectionnonumber{\large\bf Übungsaufgabe: Verkettete Listen}
\begin{frame}
\shownosectionnonumber
Schreiben Sie eine Funktion, die eine verkettete Liste\\
in die umgekehrte Reihenfolge bringt.
\begin{enumerate}[\quad(a)]
\item
Die Funktion soll möglichst schnell arbeiten.\\
Auf den Speicherverbrauch kommt es nicht an.
\item
Die Funktion soll möglichst wenig Speicher verbrauchen.\\
Auf die Rechenzeit kommt es nicht an.
\item
Wandeln Sie die einfach verkettete Liste\\
in eine doppelt verkettete Liste um.
\end{enumerate}
Geben Sie für alle Funktionen das Landau-Symbol\\
für die Laufzeit und für den Speicherverbrauch an.
\end{frame}
\end{document}
../common/landau-symbols-2.pdf
\ No newline at end of file
../common/landau-symbols.pdf
\ No newline at end of file
../common/logo-hochschule-bochum-cvh-text.pdf
\ No newline at end of file
../common/logo-hochschule-bochum.pdf
\ No newline at end of file
../common/pgslides.sty
\ No newline at end of file
Modified BSD License
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials
provided with the distribution.
3. The name of the author may not be used to endorse or promote
products derived from this software without specific prior
written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This diff is collapsed.
This diff is collapsed.
Lecture Notes and Examples on Algorithmns and Data Structures in C/C++
Copyright (C) 2018 Peter Gerwinski <peter@gerwinski.de>
These documents are free software; you can redistribute them and/or
modify them under the terms and conditions of the following licenses:
*.tex: scripts and slides
- either the GNU General Public License, version 3
or, at your option, any later version,
- or the Creative Commons Attribution-ShareAlike 3.0
Unported License
*.c, *.h, Makefile*: programming examples
- either the Modified BSD License,
- or the Creative Commons Attribution-ShareAlike 3.0
Unported License
These documents are distributed in the hope that they will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
licenses for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file GNU-GPL-3. If not, see
<http://www.gnu.org/licenses/>.
You should have received a copy of the Modified BSD License
along with this document; see the file BSD-MODIFIED. If not,
see <http://www.xfree86.org/3.3.6/COPYRIGHT2.html#5>.
You should have received a copy of the Creative Commons
Attribution-ShareAlike 3.0 Unported License along with
this document; see the file CC-BY-SA-3.0. If not, see
<http://creativecommons.org/licenses/>.
This diff is collapsed.
File added
\documentclass{article}
\usepackage{pgscript}
\usepackage{pstricks,pst-plot}
\psset{unit=1cm}
\pagestyle{empty}
\setlength{\textwidth}{4cm}
\setlength{\textheight}{7cm}
\begin{document}
\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(120,190){\mbox{$2^n$}}
\psplot[linecolor=red,plotpoints=200]{1}{175}{0.6 2 x ln x ln 0.0000001 add ln mul exp mul}
\color{red}
\put(110,215){\mbox{$2^{\sqrt{\log n\,\cdot\,\log\log n}}$}}
\color{black}
\psplot[plotpoints=200]{0}{190}{x x mul 0.005 mul}
\put(190,190){\mbox{$n^2$}}
\color{red}
\psplot[linecolor=red,plotpoints=200]{1}{190}{x ln x mul 0.1 mul}
\put(195,100){\mbox{$n \log n$}}
\psplot[linecolor=red,plotpoints=200]{1}{190}{x ln x ln mul 2.3 mul}
\put(195,57.5){\mbox{$(\log n)^2$}}
\color{black}
\psplot[plotpoints=200]{0}{190}{x 0.4 mul}
\put(195,75){\mbox{$n$}}
\psplot[plotpoints=200]{1}{190}{x ln 10 mul}
\put(195,40){\mbox{$\log n$}}
\psplot[plotpoints=200]{1}{190}{30}
\put(195,25){\mbox{$1$}}
\put(205,0){\makebox(0,0)[l]{$n$}}
% \put(-10,210){\makebox(0,0)[l]{$g(n)$}}
\put(-10,210){\makebox(0,0)[l]{$\mathcal{O}\bigl(g(n)\bigl)$}}
\end{pspicture}
\end{document}
This diff is collapsed.
File added
\documentclass{article}
\usepackage{pgscript}
\usepackage{pstricks,pst-plot}
\psset{unit=1cm}
\pagestyle{empty}
\setlength{\textwidth}{4cm}
\setlength{\textheight}{7cm}
\begin{document}
\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(120,190){\mbox{$2^n$}}
\psplot[plotpoints=200]{0}{190}{x x mul 0.005 mul}
\put(190,190){\mbox{$n^2$}}
\psplot[plotpoints=200]{1}{190}{x ln x mul 0.1 mul}
\put(195,100){\mbox{$n \log n$}}
\psplot[plotpoints=200]{0}{190}{x 0.4 mul}
\put(195,75){\mbox{$n$}}
\psplot[plotpoints=200]{1}{190}{x ln 10 mul}
\put(195,50){\mbox{$\log n$}}
\put(205,0){\makebox(0,0)[l]{$n$}}
% \put(-10,210){\makebox(0,0)[l]{$g(n)$}}
\put(-10,210){\makebox(0,0)[l]{$\mathcal{O}\bigl(g(n)\bigl)$}}
\psplot[plotpoints=200]{1}{190}{30}
\put(195,25){\mbox{$1$}}
\end{pspicture}
\end{document}
File added
File added
% pgscript.sty - LaTeX Settings for Lecture Notes
% Copyright (C) 2012, 2015, 2017 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/>.
\usepackage{amsfonts}
\usepackage[colorlinks,allcolors=blue]{hyperref}
\usepackage[british,german]{babel} % Yes, really "german" and not "ngerman".
\usepackage[utf8]{luainputenc} % Without this, umlauts are broken. Weird.
\usepackage{microtype}
\usepackage[T1]{fontenc}
\usepackage{times}
\usepackage{helvet}
\renewcommand*\familydefault{\sfdefault}
\usepackage{graphicx}
\usepackage{ifluatex}
\usepackage{xcolor}
\usepackage{enumerate}
%% Repair kerning: Automatically insert "\kern{-0.15em}" between "//" % (in URLs).
%% PG20151206: This seems unnecessary here. Maybe due to \sf?
%\ifluatex
%\directlua{
% local glyph = node.id ("glyph")
% local function my_kerning (head)
% for t in node.traverse (head) do
% if t.id == glyph and t.char == 47 then
% if t.next
% and t.next.next
% and t.next.next.id == glyph
% and t.next.next.char == 47 then
% local k = node.new ("kern")
% k.kern = tex.sp ("-0.15em")
% k.next = t.next
% k.prev = t
% t.next.prev = k
% t.next = k
% end
% end
% end
% node.kerning (head)
% end
% luatexbase.add_to_callback ("kerning", my_kerning, "URL kerning")
%}
%\fi
\definecolor{blendedblue}{rgb}{0.2,0.2,0.7}
\definecolor{darkgreen}{rgb}{0.0,0.3,0.0}
\definecolor{darkred}{rgb}{0.7,0.0,0.0}
\definecolor{darkgrey}{rgb}{0.4,0.4,0.4}
\newcommand{\breath}{\bigskip\goodbreak}
\newcommand{\subsubsubsection}[1]{\breath\par\textbf{#1}\nopagebreak\par}
\newenvironment{experts}{\color{darkgrey}}{}
\newenvironment{whiteout}{\definecolor{darkgreen}{rgb}{1.0,1.0,1.0}%
\definecolor{darkred}{rgb}{1.0,1.0,1.0}%
\color{white}}{}
\urlstyle{sf}
\newcommand{\file}[1]{{\color{blendedblue}#1}}
\newcommand{\textarrow}{{\boldmath $\longrightarrow$}}
\newcommand{\arrowitem}{\item[\textarrow]}
\newcommand{\newterm}[1]{\emph{\color{darkgreen}#1}}
\newcounter{exercise}
\newcommand{\exercise}[1]{\addtocounter{exercise}{1}\subsection*{Aufgabe \arabic{exercise}: #1}}
\newcommand{\solution}{\subsubsection*{Lösung}}
\newcommand{\gitfile}[3]{\href{https://gitlab.cvh-server.de/pgerwinski/#1/raw/master/#2/#3}{\file{#3}}}
\usepackage{listings}
\lstset{basicstyle=\color{blendedblue},
language=C,
captionpos=b,
gobble=4,
xleftmargin=1em,
columns=fullflexible,
moredelim=**[is][\color{red}]{¡}{¿}}
\lstdefinestyle{numbered}{xleftmargin=2em,
numbers=left,
numberstyle=\footnotesize\color{gray}}
\lstdefinestyle{terminal}{basicstyle=\ttfamily\color{darkgreen},
language={},
columns=fixed,
moredelim=**[is][\color{darkred}]{¡}{¿},
moredelim=**[is][\color{blendedblue}]{°}{¿},
moredelim=**[is][\sffamily\it\lstset{columns=fullflexible}]{²}{¿}}
\lstdefinestyle{cmd}{basicstyle=\ttfamily\color{darkred},
language={},
columns=fixed,
moredelim=**[is][\color{darkgreen}]{¡}{¿},
moredelim=**[is][\color{blendedblue}]{°}{¿},
moredelim=**[is][\sffamily\it\lstset{columns=fullflexible}]{²}{¿}}
\setlength{\textwidth}{16.5cm}
\setlength{\textheight}{26.0cm}
\setlength{\hoffset}{-1.5cm}
\setlength{\voffset}{-3.0cm}
\setlength{\parindent}{0pt}
\setlength{\parskip}{\medskipamount}
\setlength{\unitlength}{1cm}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment