CSCI 256
Design and analysis of algorithms
Assignment 2

Due Wednesday, 2/14/2001


Numbered problems are from Cormen, Leiserson, and Rivest. You should do all of the problems, but only turn in those from the second section..

Practice problems:

  1. Compute the running time of the following program. Only count the execution time of SimpleStatement inside the innermost loop. You may assume it takes one unit of time to execute.

        algorithm something(n)
           for i = 1 to sqrt(n) do
              for j = sqrt(n) downto 1 do
    	     for k = 1 to j do
    	        SimpleStatement;
        
    Technically the sqrt(n) should be floor(sqrt(n)), but we can ignore that for the purposes of this problem. See the analysis of Insertion-sort on page 8 of the text for an example (except you need not use constants or keep track of anything but the executions of SingleStatement -- even the computations of sqrt(n) should be considered to be free).

  2. Problem 2-3 on pg 38 of CLR. You need only consider the functions (sqrt(2))lg n, n2, n!, (3/2)n, lg2 n, lg(n!), n1/lg n, and 2lg n. Give reasons for the ordering.

  3. Problem 2-4 a, b, d, g on pg 39 in CLR.

  4. Problem 4.1-3 on pg 57 of CLR.

  5. Problem 4-1 a, c, f, g on pg 72 of CLR.

Problems to be turned in:

  1. Problem 2.2-4 on pg 37 of CLR. Use Stirling's approximation (equation 2.11 on page 35).

  2. Solve the recurrence T(0) = 0, T(n) = 2*T(n-1) + 1 for n > 0. You may use substitution to guess the answer, but prove the answer is correct by induction.

  3. Solve the recurrence T(1) = 1, T(n) = 2*T(n/4) + lg n for n > 1. Do not use the master method. Instead use substitution to come up with an exact answer. Finally express the answer in as simple big-Theta form as possible. You need not prove it by induction. Hint: Only worry about n of the form 4k.


Back to:

  • CS256 home page
  • Kim Bruce's home page
  • CS Department home page
  • kim@cs.williams.edu