\documentclass{beamer}
%
%
\makeatletter
\@ifundefined{lhs2tex.lhs2tex.sty.read}%
  {\@namedef{lhs2tex.lhs2tex.sty.read}{}%
   \newcommand\SkipToFmtEnd{}%
   \newcommand\EndFmtInput{}%
   \long\def\SkipToFmtEnd#1\EndFmtInput{}%
  }\SkipToFmtEnd

\newcommand\ReadOnlyOnce[1]{\@ifundefined{#1}{\@namedef{#1}{}}\SkipToFmtEnd}
\usepackage{amstext}
\usepackage{amssymb}
\usepackage{stmaryrd}
\DeclareFontFamily{OT1}{cmtex}{}
\DeclareFontShape{OT1}{cmtex}{m}{n}
  {<5><6><7><8>cmtex8
   <9>cmtex9
   <10><10.95><12><14.4><17.28><20.74><24.88>cmtex10}{}
\DeclareFontShape{OT1}{cmtex}{m}{it}
  {<-> ssub * cmtt/m/it}{}
\newcommand{\texfamily}{\fontfamily{cmtex}\selectfont}
\DeclareFontShape{OT1}{cmtt}{bx}{n}
  {<5><6><7><8>cmtt8
   <9>cmbtt9
   <10><10.95><12><14.4><17.28><20.74><24.88>cmbtt10}{}
\DeclareFontShape{OT1}{cmtex}{bx}{n}
  {<-> ssub * cmtt/bx/n}{}
\newcommand{\tex}[1]{\text{\texfamily#1}}	% NEU

\newcommand{\Sp}{\hskip.33334em\relax}
\newcommand{\NB}{\textbf{NB}}
\newcommand{\Todo}[1]{$\langle$\textbf{To do:}~#1$\rangle$}

\EndFmtInput
\makeatother
%
\author{Piyush P Kurur\\
  Office no: 224\\
  Dept. of Comp. Sci. and Engg.\\
  IIT Kanpur}


\newcommand{\Token}[2][]{\node(#2#1)[token]{#2};}
\newcommand{\Symbol}[2][]{\node(#2#1)[symbol]{#2};}
\newcommand{\Point}[1]{\node(#1)[point]{#1};}

\usepackage{tikz}
\usetikzlibrary{positioning,shapes,chains,fit}
\usetikzlibrary{shapes.symbols}
\usetikzlibrary{matrix}
\usetikzlibrary{backgrounds}
\usetikzlibrary{shapes.geometric}

\usepackage{pgfkeys}
\usepackage{multicol}
\pgfkeys %
    {%
      /tikz/coin/.style={
        rectangle,
        minimum height=2.5mm,
        minimum width=1cm,
        draw=black,
        fill=black!20,
        rounded corners
      },
      /tikz/towercolor/.style={
        fill=black!90
      },
      /tikz/towerbase/.style={
        trapezium,
        trapezium angle=45,
        trapezium stretches=true,
        towercolor,
        minimum width=7.5mm,
        minimum height=2.5mm,
      },
      /tikz/tower/.style={
        rectangle,
        rounded corners,
        towercolor,
        minimum width=2.5mm,
        minimum height=17.5mm,
      }
    }

\title{Fundamentals of Computing: Lecture 9}
\date{August 17, 2009}
\begin{document}
\begin{frame}
\maketitle
\end{frame}

\begin{frame}
  \frametitle{Summary of last class}
  \pause
  \begin{itemize}
  \item We looked at the tower of hanoi problem.
    \pause
  \item We gave a recursive solution to that problem.
    \pause
  \end{itemize}
\end{frame}

\begin{frame}
  \begin{block}{Another example}
    Given an integer $n$ print the sequence
    $n, n-1,\dots,1, 0, 1, \ldots, n - 1, n$
  \end{block}
\end{frame}
\begin{frame}
  \begin{block}{Using iteration}
    \begin{tabbing}\tt
~~~~~~~\char35{}~include\char60{}stdio\char46{}h\char62{}\\
\tt ~~~~~~~void~downUp\char40{}int~n\char41{}\\
\tt ~~~~~~~\char123{}\\
\tt ~~~~~~~~~for\char40{}int~i~\char61{}~n\char59{}~i~\char62{}~0\char59{}~i\char45{}\char45{}\char41{}\\
\tt ~~~~~~~~~\char123{}\\
\tt ~~~~~~~~~~~printf\char40{}\char34{}\char37{}d\char44{}~\char34{}\char44{}~i\char41{}\char59{}\\
\tt ~~~~~~~~~\char125{}\\
\tt ~~~~~~~~~printf\char40{}\char34{}0\char34{}\char41{}\char59{}\\
\tt ~~~~~~~~~for\char40{}int~i~\char61{}~1\char59{}~i~\char60{}\char61{}~n\char59{}~i~\char43{}\char43{}\char41{}\\
\tt ~~~~~~~~~\char123{}\\
\tt ~~~~~~~~~~~printf\char40{}\char34{}\char44{}~\char37{}d\char34{}\char44{}~i\char41{}\char59{}\\
\tt ~~~~~~~~~\char125{}\\
\tt ~~~~~~~\char125{}
\end{tabbing}
  \end{block}
\end{frame}

\begin{frame}
  Let $S_n$ denote the sequence $n,\ldots, 0 , \ldots, n$.
   \begin{block}{Recursive definition}
    \begin{eqnarray*}
      S_{0} & = &  0\\
      S_{n} & = & n, S_{n-1}, n
    \end{eqnarray*}
  \end{block}
  \pause
  \begin{tabbing}\tt
~~~~~void~downUpRec\char40{}int~n\char41{}\\
\tt ~~~~~\char123{}\\
\tt ~~~~~~~if\char40{}n~\char60{}\char61{}~0\char41{}~\\
\tt ~~~~~~~\char123{}\\
\tt ~~~~~~~~~printf\char40{}\char34{}0\char34{}\char41{}\char59{}\\
\tt ~~~~~~~~~return\char59{}\\
\tt ~~~~~~~\char125{}\\
\tt ~~~~~~~printf\char40{}\char34{}\char37{}d\char44{}~\char34{}\char44{}~n\char41{}\char59{}~\\
\tt ~~~~~~~downUpRec\char40{}n\char45{}1\char41{}\char59{}\\
\tt ~~~~~~~printf\char40{}\char34{}\char44{}~\char37{}d\char34{}\char44{}~n\char41{}\char59{}\\
\tt ~~~~~\char125{}
\end{tabbing}
\end{frame}

\begin{frame}
\begin{block}{The \text{\tt main} function}
  \begin{tabbing}\tt
~~~~~void~downUpRec\char40{}int\char41{}\char59{}\\
\tt ~~~~~void~downUp\char40{}int~\char41{}\char59{}\\
\tt ~\\
\tt ~~~~~int~main\char40{}\char41{}\\
\tt ~~~~~\char123{}~\\
\tt ~~~~~~~int~n\char59{}\\
\tt ~~~~~~~printf\char40{}\char34{}enter~the~number\char58{}~\char34{}\char41{}\char59{}\\
\tt ~~~~~~~scanf\char40{}\char34{}\char37{}d\char34{}\char44{}\char38{}n\char41{}\char59{}\\
\tt ~~~~~~~printf\char40{}\char34{}Iterative\char58{}\char92{}t\char34{}\char41{}\char59{}\\
\tt ~~~~~~~downUp\char40{}n\char41{}\char59{}\\
\tt ~~~~~~~printf\char40{}\char34{}\char92{}nRecursive\char58{}\char92{}t\char34{}\char41{}\char59{}\\
\tt ~~~~~~~downUpRec\char40{}n\char41{}\char59{}\\
\tt ~~~~~~~printf\char40{}\char34{}\char92{}n\char34{}\char41{}\char59{}\\
\tt ~~~~~\char125{}
\end{tabbing}
\end{block}
\end{frame}
\begin{frame}
  \frametitle{Separate compilation}
  \begin{itemize}
  \item Create a file \text{\tt downUp\char46{}c} that contains the 
    definition of the function \text{\tt void~downUp\char40{}int\char41{}}
  \item Create a file \text{\tt downUpRec\char46{}c} that contains the
    definition of the function \text{\tt void~downUpRec\char40{}int\char41{}}
  \item Create a file \text{\tt main\char46{}c}
  \end{itemize}
  
  \begin{block}{Compiling}
    \begin{tabbing}\tt
~~~~~~~\char36{}~gcc~\char45{}std\char61{}c99~main\char46{}c~downUp\char46{}c~downUpRec\char46{}c\\
\tt ~~~~~~~\char36{}~gcc~\char45{}std\char61{}c99~\char45{}c~downUp\char46{}c\\
\tt ~~~~~~~\char36{}~gcc~\char45{}std\char61{}c99~\char45{}c~downUpRec\char46{}c\\
\tt ~~~~~~~\char36{}~gcc~\char45{}std\char61{}c99~main\char46{}c~downUp\char46{}o~downUpRec\char46{}o
\end{tabbing}
  \end{block}
\end{frame}
\end{document}


