There are five questions for 100 total points. All are based on lectures 1-3, and thus on Chapters 1 and 2 of the Adler notes.
Students are responsible for understanding and following the academic honesty policies indicated on the course main page.
Edits in green made 15 September 2005.
Edits in purple made 19 September 2005.
Edits in orange made 20 September 2005.
Problem 1.1 (10): Suppose that f and g are increasing functions from the positive reals to the positive reals, and that both are polynomially bounded. (That is, there exists a number k such that both f and g are O(nk.) Suppose also that there exists a number b, with b>1, and an integer i0, such that f(bi)=g(bi) for all integers i such that i>i0.
Prove that if f is one of the functions arising from the Master Theorem, that is, f = Θ(nα) or f = Θ(nαlog n) for some positive real number α, then f=Θ(g). Is this conclusion true without the condition that f and g are polynomially bounded? Prove your answer. Up to five points extra credit for a counterexample to the original question.
Problem 1.2 (10): Let T(n) be a function defined by the recurrence T(n) = 2T(n/2) + Θ(n log n), with T(n) = O(1) for n ≤ c. Prove that T(n) = Θ(n log2 n).
Problem 1.3 (20): (Stolen from CLRS, p. 161) The Stoogesort algorithm sorts the elements of an array. There is a recursive method stoogeSort(A,i,j) that sorts the elements from A[i] through A[j] if i ≤ j.
void stoogeSort (Comparable[] A, int i, int j);{
if (A[i] > A[j])
exchange A[i] and A[j];
if (i+1 < j) {
k = floor((j-i+1)/3);
stoogeSort (A,i,j-k);
stoogeSort (A,i+k,j);
stoogeSort (A,i,j-k);}}
(a,10) Prove that for any array A whose size is any positive integer n, stoogeSort(A,0,n-1) correctly sorts A.
(b,10) Form a recurrence for the running time of Stoogesort, and solve it using the Master Theorem. (CLRS ask whether its authors, Profs. Howard, Fine, and Howard, deserve tenure.)
Problem 1.4 (30): The majority element problem is to input an array of n objects and return the element, if any, that occurs more than n/2 times in the array. If there is no such element, the algorithm says so.
(a,10) If the elements are Comparable
objects (and any two may be compared),
there is a well-known
algorithm to find their median in O(n) time. Explain how to solve the majority
element problem in O(n) time
with the use of this algorithm.
(You may treat the linear-time median algorithm as a black box but you must
account for the time it takes.)
(b,20)
Now suppose the objects only support an equals
method. Show how
to solve the majority element problem in O(n) time.
(Hint: There are explanations
of this on the web but one of the first I found was stated badly -- make sure you are
very clear in your own explanation. This can be thought of as
a divide and conquer problem of a sort,
but does not necessarily use the Master Theorem.
Problem 1.5 (30): A number in binary notation can be identified with a polynomial that has the same coefficients, for example, if A is the sum of ai2i, then A(x) is the sum of aixi and A = A(2). With the FFT, we can take two polynomials A(x) and B(x) and find C(x), where C=AB, in O(n log n) time. Since C(2) = A(2)B(2), computing C(x) should help us multiply the binary integers A and B. But it's not that simple.
(a,10) Describe how to go from C, given by its coefficients as integers, to the binary representation of C. How large could the coefficients be? How long does this take?
(b,10) Discuss the O(n log n) running time of the FFT polynomial multiplication in terms of bit operations. What would you need to know to determine the number of bit operations needed to implement it on the n-bit integers A and B above?
(c,10) If p is a prime number of the form kn+1, algebra tells us that in the ring of integers modulo p there is an n'th root of unity -- a number g such that gn = 1 (mod p) and ga ≠ 1 (mod p) for any a with 1≤a<n. Assume that such a prime exists, and that we can add and multiply numbers modulo p in O(log n) bit operations. Describe how to multiply two n-bit binary integers by FFT on their respective polynomials, and analyze the running time of your method. (Hint: You may want to precompute a table of the powers of g.)
Last modified 20 September 2005