
\documentclass[12pt,fleqn]{article}

\usepackage[letterpaper,hmargin=1in,vmargin=1in]{geometry}

\newcommand{\comment}[1]{}
\newcommand{\binomial}[2]{\left({{#1} \above 0pt {#2}}\right)}
\newcommand{\var}[1]{\mbox{\em #1}}

\begin{document}

\setcounter{page}{1}
\thispagestyle{empty}

\begin{center}
\LARGE
Problem Set 1\\
\normalsize 
\ \\
CS 5633 -- Spring 2007 \hfill assigned January 22, 2007 \\
Tom Bylander, Instructor \hfill first due date February January 31, 2007 \\
 \hfill second due date February 7, 2007 \\
\end{center}

\normalsize

Your solutions must be submitted as a document to WebCT.

\begin{enumerate}

\item What are the loop invariants of the outer and inner loops
of the algorithm below?

\begin{tabbing}
{\sc Selection-Sort}$(A)$ \\
\ \ \ \ \=\+\kill
\var{n} $\leftarrow$ $\var{length}(A)$ \\
{\bf for} \= $i$ $\leftarrow$ 1 {\bf to} $n-1$ {\bf do} \\
\> \= \var{min} $\leftarrow$ $i$ \\
\> {\bf for} \= $j$ $\leftarrow$ $i + 1$ {\bf to} $n$ {\bf do} \\
\>\>
  {\bf if} $A[j] < A[\var{min}]$ {\bf then} \var{min} $\leftarrow$ $j$ \\
\> exchange $A[i]$ $\leftrightarrow$ $A[\var{min}]$
\end{tabbing}

\item Suppose $n$ is a positive integer that we wish to encode to
  within 0.1\% accuracy?  Asymptotically bound the number of bits that
  are needed.  Justify your answer.

\item Provide the simplest function $g(n)$ such that $\sum_{i=1}^n
  (n-i)/i$ is $\Theta(g(n))$.

\item Rank the following 12 functions by order of growth.  Note
any pairs of functions such that $f(n)$ is $\Theta(g(n))$.

\begin{list}{}{}
\item $f_1(n) = \lg n$

\item $f_2(n) = n^2$

\item $f_3(n) = 2^n$

\item All the functions $f_i(f_j(n))$ for $i \in \{1,2,3\}$ and
$j \in \{1,2,3\}$
\end{list}

\item Use mathematical induction to show that when $n$ is an exact
power of 2, the solution of the recurrence
\[T(n) = \left\{
\begin{array}{ll}
a & \mbox{if $n = 1$,} \\
2 T(n/2) + n & \mbox{if $n = 2^k$, for some $k > 0$}
\end{array}
\right.\]
is $T(n) = n (a + \lg n)$.

\item Consider recurrences of the form $T(n) = a T(n/b) + n^c$.
Fill in the following table with asymptotic bounds in
$\Theta$-notation.

\[\begin{array}{ccc|l}
a & b & c & \mbox{Asymptotic Bound} \\ \hline
1 & 2 & 0 & \\
1 & 2 & 1 & \\
1 & 2 & 2 & \\
2 & 2 & 0 & \\
2 & 2 & 1 & \\
2 & 2 & 2 & \\
3 & 2 & 0 & \\
3 & 2 & 1 & \\
3 & 2 & 2 & 
\end{array}\]


\item The following four exercises are concerned with the number of
  changes to a variable in an algorithm that keeps track of the
  current median.
\begin{enumerate}

\item Define a median of $n$ numbers to be any number $m$ such that
  $\lceil n/2 \rceil$ numbers are less than or equal to $m$ and $\lceil n/2
  \rceil$ numbers are greater than or equal to $m$.  Using this
  definition, provide 5 different medians of the numbers $1, 2, 3, 4,
  5, 6$.

\item In pseudocode, write an algorithm that finds the median of an
  array of $n$ numbers by a loop that keeps track of the median of the
  first $i$ numbers.  Do not change the value of the current median
  if it satisfies the above definition.  For example, if the array is 
  $1, 5, 6, 2, 3, 4$, the value of the current median should be the
  sequence $1, 1, 5, 5, 3, 3$.

\item
 What is the minimum and maximum number of changes to the current
 median for an array of size $n$?  Provide examples illustrating both
 cases. 

\item
 In this exercise, we want to prove that the expected number of changes
 is greater than $n/4$.  Suppose that the $n$ numbers in the array are
 distinct and in random order.  Suppose $m_i$ is the median of the
 first $i$ numbers where $i$ is odd.  Derive a bound on the
 probability that $m_{i+2} \neq m_i$.  Hint: The next two numbers
 might be both lower than $m_i$ or both higher than $m_i$.

\end{enumerate}

\end{enumerate}

\end{document}
