You are on page 1of 2

CS38, Spring 2011 Introduction to Algorithms Prof. Alexei Kitaev Problems 1.

Exercises:

Problem set #1 Due Friday April 8, 2011 at 5pm in the box in the computer lab.

a) (4 points) Sort the following functions in order of their asymptotic growth (i.e., the O-relation means , the -relation means , and means =: n, n log n, (log2 n)n , (ln n)n , nln n , 2n , n!, 2n , n ln(n!), ln 2n . n

You may use the Stirling approximation: n! b) (3 points) Solve the recurrence T (n) = 3T (n/2) + O(n2 ).

2n(n/e)n .

c) (3 points) Solve the recurrence T (n) = T (n/3) + T (2n/3) + O(n). 2. CLRS problem 2-2 (Correctness of bubblesort): a) (1 point) b) (4 points) c) (4 points) d) (1 point) 3. Let a sequence S = (x1 , . . . , xn ) be sorted. A corresponding sequence A = (xf (1) , . . . , xf (n) ) is called k-almost sorted if |f (i) i| k for all i = 1, . . . , n. a) (10 points) Find an algorithm that sorts a k-almost sorted sequence in time O(n log k). You dont need to reason using pseudocode; just give a higher-level correctness proof. Hint: Use merge-sort as a subroutine in your algorithm. b) (5 points) Prove the lower bound (n log k). Hint: Use the standard lower bound (n log n) for sorting. If you want to be really rigorous (which is not required), you need to apply the counting argument used in the proof of the standard bound to a subset of almost sorted sequences. 4. A pebble game is the following mathematical puzzle. There is an innite row of cells numbered 0, 1, 2, . . .. Initially, there is a pebble in cell 0; the other cells are empty. The player can put or remove a pebble at cell s if there is a pebble at cell s 1. 1

a) (10 points) Show that given k pebbles (in addition to the one mentioned above), the player can reach a position in which cell n = 2k 1 is occupied. How many moves are necessary to complete this task? (To answer this question, you need to nd and solve a recursion.) Represent the result in the form (n ) for some constant . b) (bonus 10 points) Let be a positive real number. Prove that it is possible to reach cell n in O(n1+ ) moves, using O(log n) pebbles.

You might also like