\documentstyle{report}
\pagestyle{myheadings}
\def\headlineaux{\sc Math 220/317: Programming II/Data Structures 
\hrulefill
}
\markboth{\headlineaux}{\headlineaux}

\begin{document}
\begin{titlepage}\begin{centerline}{\Huge \framebox{Burt Rosenberg}}
\end{centerline}\end{titlepage}

\section*{Final Exam}

\begin{enumerate}
\item
How do these two code blocks differ:
\begin{verbatim}
    /* First code block */
    i = 0 ;
    while (i*i<N) {
       i = i+1 ;
    }
\end{verbatim}
\begin{verbatim}
    /* Second code block */
    i = 0 ;
    do {
       i = i+1 ;
    } while (i*i<N) ;
\end{verbatim}
{\sc Hint:} They differ only for certain values of $N$.

\item
Logical equivalence of formulas can be useful to simplify your code.
Show that these two code blocks function equivalently:
\begin{verbatim}
     /* First code block */
     if( !a ) {
        if ( !b ) { 
           printf("The condition on a and b is satisfied.\n") ;
        }
     }   
\end{verbatim}
\begin{verbatim}
    /* Second code block */
    if ( a || b ) {
       }
    else {
       printf("The condition on a and b is satisfied.\n") ;
    }
\end{verbatim}
{\sc Hint:} Use logical deduction to show that, as a function of the integer
variables $a$ and $b$, the printf is run in the first code block only
if for the same values of $a$ and $b$, it would run in the second code block.

\newpage
\item
Although logical equivalent, the following two code blocks {\em do not}
function equivalently. State why.
\begin{verbatim}
    /* First code block */
    if ( a ) {
       if ( b ) {
          printf("The condition on a and b is satisfied.\n") ;
       }
    }
\end{verbatim}
\begin{verbatim}
    /* Second code block */
    if ( b && a ) {
       printf("The condition on a and b is satisfied.\n") ;
    }
\end{verbatim}

\item
What does this program do?

\begin{verbatim}
  int mystery( int n, int m) {
     int j, k, l ;
     if ( n<=0 ) { return(0) ; }
     k = 0 ;
     j = 0 ;
     if ( n%2 ) {
        j = m ;
        k = 1 ; }
     l = mystery( (n-k)/2,m ) ;
     return( l+l+j ) ;
  }
\end{verbatim}

\item
For every integer $N$, does this program eventually print out ``Done'' then stop?
\begin{verbatim}
  #include<stdio.h>
  #define N 10
  int main(int argc, char * argv[] ) {
     int n ;
     n = N ;
     while ( n!= 1 ) {
        if ( n%2 ) { n = 3*n-1 ; }
        else n = n/2 ;
     }
     printf("Done\n") ;
  }
\end{verbatim}
\end{enumerate}
\end{document}
