\documentclass[11pt]{article}

\usepackage{fullpage}
\usepackage{graphicx}
\usepackage{clrscode3e}




\begin{document}

\title{Algorithms Lab 5}

\date{}
\maketitle



The in-lab problems are to be solved during the lab time.  Work with
your team, but write your solutions individually. You do not need to
turn in your answers, only discuss them with me. Ask me for feedback.
%on how you write your answers.

The homework problem set is due in one week. Work with your team, but
write your solutions individually. List the people with whom you
discussed the problems clearly on the first page.


%%\vspace{1cm}
\section{ In lab exercises}


\begin{itemize}

\item (CLRS 9.3-1) In the algorithm SELECT, the input elements are
  divided into groups of 5.  Will the SELECT algorithm work in linear
  time if they are divided into groups of 7?  Argue that SELECT does
  not run in linear time of groups of 3 are used. 


\item (CLRS 9.3-3) Show how QuickSort can be made to run in $O(n \lg n)$ time in
  the worst case, assuming that all elements are distinct.



\item (CLRS 9.3-5) Suppose that you have a ``black-box'' worst-case linear time
  median subroutine.  Give a simple, linear time algorithm for SELECT
  (i). 



\item  (GT C-4.12) Show that any comparison-based sorting algorithm
  can be made to be stable, without affecting the  asymptotic running
  time of the algorithm.   (Hint: Change the way elements are compared
  to each other.)

\item  (GT  C-4.15) Let $S_1, S_2, ... S_k$ be $k$ different sequences
  whose elements have integer keys in the range $[0, N-1]$, for some
  parameter $N \ge 2$.  Describe an algorithm running in $O(n+N)$ time
  for sorting all the sequences  (not as a union),  where $n$ denotes
  the total size of all sequences. 

\end{itemize} 



\section{Homework problems}

\begin{enumerate} 

\item Let $A$ be a list of $n$ (not necessarily distinct) integers.
  Describe an $O(n)$-algorithm to test whether any item occurs more
  than $\lceil n/2 \rceil$ times in $A$. Your algorithm should use
  $O(1)$ additional space. 


\item (GT C-4.23, CLRS 9.3-7) Given an unordered sequence $S$ of $n$
  comparable elements, describe an efficient method for finding the
  $\lceil \sqrt n \rceil$ items whose rank in an ordered version of
  $S$ is closest to that of the median.  What is the running time of
  your method?

\item (GT C-4.27, CLRS 9.3-6) Given an unsorted sequence $S$ of $n$
  elements, and an integer $k$, give an $O(n \lg k)$ expected time
  algorithm for finding the $O(k)$ elements that have rank $\lceil n/k
  \rceil$, $2\lceil n/k \rceil$, $3\lceil n/k \rceil$, and so on.


\item  (CLRS 9-3.9) Professor Olay is consulting for an oil company,
  which is planning a large pipeline running east to west through an
  oil field of $n$ wells.The company wants to connect a spur pipeline
  from each well directly to the main pipeline along a shortest route
  (eitehr north or south), as shown in textbook CLRS figure 9.2. Given
  the x- and y-coordinates of the wells, show how the professor should
  pick the optimal location of the main pipeline, which would be teh
  one that minimizes the total length of the spurs. Show how to
  determine the optimal location in linear time.  Hint: Assume professor
  Olay is a computer science professor and her specialty is
  algorithms!

  

\end{enumerate}


\end{document}
%%% Local Variables: 
%%% mode: latex
%%% TeX-master: t
%%% End: 
