\documentclass{beamer}

%\documentclass[handout]{beamer}
%\usepackage{pgfpages}
%\pgfpagesuselayout{2 on 1}[a4paper,border shrink=5mm]
%\pgfpagesuselayout{4 on 1}[a4paper,border shrink=5mm,landscape]

\usetheme{Boadilla}

\title{FT507 C++/C Programming}
\subtitle{Algorithms}
\author{Carsten Svaneborg}
\institute{FKF}
\date{\today}

\begin{document}

\begin{frame}
\titlepage
\end{frame}

%\begin{frame}
%\frametitle{Outline}
%\tableofcontents
%\end{frame}

\begin{frame}\frametitle{Algorithm}

\begin{itemize}
\item Algorithm is a step-by-step plan for solving problem.
\end{itemize}

\begin{itemize}
\item Multiply or add two numbers.   $351+134$   or $273*854$
\item Make coffee (boil water, ground coffee, ..)
\item Knit sweater
\item Build LEGO
\item Borrowing book from library.
\item Find lecture room
\item Solve linear equation
\end{itemize}

\end{frame}

\begin{frame}\frametitle{Algorithm 1}

Describe problem (often difficult!):
\begin{itemize}
\item What is the solution of the problem?
\item What input is expected?
\item What output is expected?
\end{itemize}
\end{frame}

\begin{frame}\frametitle{Algorithm 2}

Analyze the problem:
\begin{itemize}
\item What are the types of input data?
\item What coarse steps to execute to reach goal.
\item How do we know, if we are done?
\item Output: screen / file data?
\item Identify and handle special cases.
\end{itemize}

Often its a good idea to simplify problem or solve several problems on a piece of paper,
to get a feeling for the structure of the problem.

\end{frame}

\begin{frame}\frametitle{Algorithm 3}

Don't start coding yet! First write down high-level solution:

\begin{itemize}
\item What are the big logical steps to solve problem
\item What are the relations between these steps
\item E.g. Pseudo-code
\item E.g. Flow-chart
\item :
\end{itemize}
\end{frame}

\begin{frame}\frametitle{Algorithm 4}

Refine and Translate into code
\begin{itemize}
\item Turn high-level description to actual code (divide and conquer)
\item Data are mapped to types / variables / arrays
\item Steps = blocks of code or functions
\item How does blocks of code / functions communicate.
\item Output to screen / file
\end{itemize}
\end{frame}


\begin{frame}\frametitle{Algorithm 5}

Often we need to iterate!
\begin{itemize}
\item Often we realise the problem was not clearly stated.
\item Often we make implicit assumptions about the problem
\item We didn't really understand the problem.
\item Need to handle additional special cases.
\item Make resilient code handling faulty user input.
\item Optimize code to run faster / use less memory.
\item Structure code for making algorithm more clear.
\item Redefine function and variable names for improved semantics
\item Generalize solution to work for a wider set of problems.
\end{itemize}
\end{frame}

\begin{frame}\frametitle{Algorithms}

So far OK for imperative programming, BUT
\begin{itemize}
\item What about stochastic/non deterministic algorithms?
\item What about recursive algorithms?
\item What about distributed algorithms?
\item What about algorithms for heterogeneous hardware?
\item What about quantum algorithms?
\end{itemize}
\end{frame}



\begin{frame}\frametitle{Example Mandelbrot}
     \includegraphics[width=0.90\columnwidth]{graphics/Mandelbrot.jpg}
\end{frame}



\begin{frame}\frametitle{Flowchart}

     \includegraphics[width=0.99\columnwidth]{graphics/algorithm_mandelbrot.pdf}
\end{frame}

\begin{frame}\frametitle{PseudoCode}

\begin{itemize}
\item set c=x+iy (x,y) pixel coordinate
\item set z=0, counter=0
\item while ($|z|<2$ and counter$<$itermax)
  \begin{itemize}
    \item $z=z^2+c$
    \item Increment counter
  \end{itemize}
\item if (counter==itermax)
  \begin{itemize}
    \item print black pixel at x,y
  \end{itemize}
\item else  
  \begin{itemize}
    \item print pixel at x,y with color related to counter.
  \end{itemize}
\end{itemize}

\end{frame}



\begin{frame}\frametitle{Example Eratosthenes}

Primes: 1,2,3,5,7,11,13,..

\end{frame}


\begin{frame}\frametitle{Flowchart}
     \includegraphics[width=0.99\columnwidth]{graphics/algorithm_eratosthenes.pdf}
\end{frame}

\begin{frame}\frametitle{PseudoCode}

\begin{itemize}
\item Read in N the maximal potential prime value.
\item Define primecandidate array [0..N-1] with all true.
\item Do
  \begin{itemize}
    \item Starting at p=2
    \item for j:
    \begin{itemize}
    \item mark primecandidate[2p] false
    \item mark primecandidate[3p] false
    \item :
    \item mark primecandidate[j*p] false
    \item as long as $j*p<N$
    \end{itemize}
    \item Find next $p$, that is not marked or $p=N$.
  \end{itemize}
\item Repeat while $p<N$;
\item Print primes that is i where primecandidate[i] is true.
\end{itemize}
\end{frame}

\begin{frame}\frametitle{Now}

\begin{itemize}
\item Root finding: Bisection
\item Root finding: Newton-Raphson
\item Solving ODEs: Euler
\item Integration: Box and trapetz
\end{itemize}
\end{frame}

\end{document}
