CS580
assignment #2 (Due: Wed. Feb. 10)
Problem
1 (10 points): Exercise
33.4-5.
Problem
2 (10 points): Problem
9-1.
Problem
3 (10 points): Exercise
9.3-1.
Problem
4 (10 points): Exercise
8.2-4.
Problem
5 (10 points): Exercise
8.3-4.
Problem
6 (10 points): Using
adversary argument, prove that any comparison sort algorithm requires Omega(n lg n) comparisons to sort
an array of n integers in worst case.
Problem
7 (10 points): We saw in
class that the SELECT algorithm can find the k th
largest element in O(n) worst-case time. Now, using
adversary argument, prove that n - 1 + min(k - 1, n -
k) is a lower bound on the number of comparisons needed to find the k th largest element in an n-element array.
Problem
8 (15 points): Consider
an n-element array A[1..n]:
(1) Give an O(n)-time
algorithm to determine if any element of A appears at least n/2 times in A. If
such an element exists, your algorithm should return its value; else it should
return NULL.
(2) Give an O(nk)-time algorithm to determine if any element of A appears
at least n/k times in A. If such an element exists, your algorithm should
return its value; else it should return NULL.
Problem
9 (15 points):
Let
be a bit string of length 5, i.e.
for
.
Consider the problem of determining whether b contains three consecutive
zeros, i.e. whether or not b contains the substring 111. We restrict our attention to those
algorithms whose only allowable operation is to peek at a bit. Obviously 5 peeks are sufficient. A decision tree argument provides the
(useless) fact that at least one peek is necessary.
(1) Use an adversary argument to show
that 4 peeks are necessary in general.
(2) Design an algorithm which solves the
problem using only 4 peeks in worst case.
Express your algorithm as a decision tree.