\documentclass{article}
\usepackage[top=1in,bottom=1in,left=1in,right=1in]{geometry}
\usepackage{fancyheadings,enumerate,xspace,amssymb}
\pagestyle{fancy}

%\usepackage{cs5114}
% macros useful for handouts and homeworks.
\newcommand{\setcourse}[1]{\newcommand{\course}{#1\xspace}}
\newcommand{\setsem}[1]{\newcommand{\sem}{#1\xspace}}
\newcommand{\setyear}[1]{\newcommand{\myyear}{#1\xspace}}
\newcommand{\sethwnum}[1]{\newcommand{\hwnum}{#1\xspace}}

\setcourse{CS 5114}
\setyear{2018}
\setsem{Fall}
\sethwnum{1}

\chead{\course (\sem \myyear): Homework \hwnum}

\newcommand{\reals}{\ensuremath{\mathbb{R}}}
\newcommand{\solution}[1]{\textbf{Solution:} #1}
\newcommand{\cut}[1]{\ensuremath{\mathnormal{}{cut}(#1)}}
\newcommand{\calg}{\ensuremath{{\cal G}}\xspace}
\newcommand{\calo}{\ensuremath{{\cal O}}\xspace}

\begin{document}
\title{\vspace{-0.5in}\textbf{Homework \hwnum}}
\author{\course (\sem \myyear)}

\date{Assigned on Monday, August 27, \myyear. \\Submit a PDF file containing your solutions on Canvas by the beginning of class on Monday, September 3, \myyear.}
\maketitle

\input{instructions}

\begin{description}

\item[Problem 1] (5 points) Solve exercise 1 in Chapter 1 (page 22 of ``Algorithm Design'' by Kleinberg and Tardos.  

  % \solution{

  % }

\item[Problem 2] (5 points) Solve exercise 2 in Chapter 1 (page 22 of ``Algorithm Design'' by Kleinberg and Tardos.  

  % \solution{

  % }

\item[Problem 3] (25 points) Consider the following algorithm to determine if a given positive interger $n$ is prime. For each integer $i$ between 2 and $\lfloor \sqrt{n} \rfloor$, check if $i$ is a factor of $n$, i.e., if dividing $n$ by $i$ leaves a remainder of $0$. If the answer is ``yes'' for any $i$, return that $n$ is composite. Otherwise, return that $n$ is prime. Answer the following questions about this algorithm.

  \begin{enumerate}[(a)]
  \item (5 points) Let us use $f(n)$ to denote size of the input to this problem. What is $f(n)$? Is $f(n) = 1$ (because there is only number in the input)? Is $f(n) = n$ (because the value of the input is $n$)? Is it something else entirely? In the last case, write down what you think this alternative is. 
  \item (10 points) What is the running time $g(n)$ of the algorithm in terms of the input size? You may assume that we can check whether if $i$ is a factor of $n$ in $O(1)$, i.e., constant, time.
    % any -> For every $d > 0$, prove that ...
  \item (10 points) Prove that $g(n) = \Omega(f(n)^d)$ for any positive value $d$. In other words, prove that the running time of this algorithm for testing primality is lower bounded by any arbitrary polynomial function of the input size. You can start from any statement in the textbook or the slides but be sure to explain how you derive your conclusion from the starting statement.
  \end{enumerate}
\emph{Note:} It is likely that you will be able to prove part (c) only if you answer part (a) correctly.

  
  % \solution{

  % }

% In Fall 2019, state that $f(n)$ and $g(n)$ should be increasing functions of $n$, to prevent solutions such as $2^-n$ and $3^-n$.
\item[Problem 4] (25 points) (20 points) Solve exercise 5 in Chapter 2  (page 68) of ``Algorithm Design'' by Kleinberg and Tardos. If you decide  that a statement is true, provide a short proof. Otherwise, provide a counterexample. \emph{Note:} If you think one of the statements is true, you should not prove it for your own choices of $f(n)$ and $g(n)$. Your proof must hold for \emph{any} pair of functions $f(n)$ and $g(n)$ where $f(n)$ is $O(g(n))$.

  % \solution{
  
  % }


\item[Problem 5] (40 points). Describe an algorithm that uses a priority queue (heap) to merge $k$ sorted lists into one sorted list. Each sorted list has $n$ integers. Neither $k$ nor $n$ is a constant. 

  To get you started, consider the following algorithm (let us call it \texttt{Algo1}):
  \begin{enumerate}
  \item Insert all the $kn$ numbers into a priority queue, with each
    number being its own key.
  \item Repeatedly report the smallest key in the queue and delete this
    value from the queue, until the queue becomes empty.
  \end{enumerate}
  What is the running time of this algorithm? 

  Now develop a heap-based algorithm (let us call it \texttt{Algo2}) that has a better running time. Describe your algorithm, prove its correctness, and provide an analysis of the  running time. Show that the running time of  \texttt{Algo1} is lower-bounded by the running time of \texttt{Algo2}, i.e., if $f_1(n, k)$ is the running time of \texttt{Algo1} and $f_2(n, k)$ is the running time of \texttt{Algo2}, then $f_1(n, k) = \Omega(f_2(n, k))$. Note that the running time of both algorithms will depend on both $n$ and $k$ since there are $nk$ numbers in total.
  
  % \solution{

  % }

\end{description}

\end{document}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:
