
\documentclass[12pt]{article}

%\setlength{\parindent}{2em}
%\setlength{\parskip}{0ex}
\usepackage[letterpaper,hmargin=1in,vmargin=1in]{geometry}

\newcommand{\comment}[1]{}
\newcommand{\var}[1]{\mbox{\em #1}}
%\pagestyle{empty}

\begin{document}

\bibliographystyle{plain}
\setcounter{page}{1}
%\pagestyle{myheadings}
%\markright{\protect\small DRAFT \hfill\today\hfill page \protect\arabic{page}}

\normalsize

\begin{center}
\LARGE
Homework 2 \\
\normalsize 
\ \\
CS 3343 -- Fall 2006 \hfill assigned August 31, 2006 \\
Tom Bylander, Instructor \hfill due September 8, 2006
\end{center}

Your solutions must be submitted as a document to WebCT.

\begin{enumerate}

\item (40 pts., 2 pts. each)
This is a variation of Exercise 2.1.1.

For each of the following algorithms, indicate (i) a natural size
metric for its inputs; (ii) its basic operation; (iii) whether the
basic operation count can be different for inputs of the same size;
(iv) an approximation of the basic operation count (worst-case) as a
constant times a simple function (in or similar to those shown in
Table 2.1, also in notes).

\begin{enumerate}
\item computing $n!$
\item finding the largest element in a list of $n$ numbers
\item Euclid's algorithm
\item sieve of Eratothenes
\item pen-and-pencil algorithm for multiplying two $n$-digit numbers
\end{enumerate}

\item (20 pts.)
For each of the following functions, demonstrate how much the function's
value will change if its argument is doubled.
\begin{enumerate}
\item $\log_2 n$
\item $\sqrt{n}$
\item $n \log_2 n$
\item $n^k$
\item $2^n$
\end{enumerate}


\item (20 pts.)
For each of the following functions, indicate the class $\Theta(g(n))$
the function belongs to.  (Use the simplest $g(n)$ in your answers.)
Prove your assertions.
\begin{enumerate}
\item $f_a(n) = (n^2 + 1)^{10}$.  Hint: show $n^{20} \leq f_a(n) \leq
  1024 n^{20}$ when $n \geq 1$.

\item $f_b(n) = \sqrt{10n^2 + 7n + 3}$.  Hint: show $3n \leq f_b(n) \leq
  4n$ when $n \geq 7$.

\item $f_c(n) = 2^{n+1} + 3^{n-1}$.  Hint: show $3^n/3 \leq f_c(n) \leq
3^n$ when $n \geq 5$.

\item $f_d(n) = \lfloor \log_2 n \rfloor$.  Hint: show $(\log_2 n)/2
  \leq f_d(n) \leq \log_2 n$ when $n \geq 4$.
\end{enumerate}

\item (20 pts.)
This is a variation of Exercise 2.3.3.

The sample variation $s^2$ of $n$ measurements $x_1, \ldots, x_n$ can be
computed as:
\[s^2 = \frac{\sum_{i=1}^n (x_i - \overline{x})^2}{n-1}\]
where $\overline{x}$ is the sample mean:
\[\overline{x} = \frac{\sum_{i=1}^n x_i}{n}\]
or $s^2$ can be computed as:
\[s^2 = \frac{\sum_{i=1}^n x_i^2 - \left(\sum_{i=1}^n x_i \right)^2 / n}
{n-1}\]

\begin{enumerate}
\item Provide pseudocode in the book's style for one of the two
  computations.

\item As a function of $n$, find the number of multiplications/divisions and
  additions/subtractions (multiplications and divisions are usually
  grouped together, ditto for additions and subtractions) that are
  required for the computing the variance according to your
  pseudocode.  You may ignore increments of loop variables in your
  counts.
\end{enumerate}

\end{enumerate}

\end{document}
