CSCI 311 -- Algorithms and Data Structures

Homework 1

38 Points

Posted Monday, 9 September 2019
Due Monday, 16 September 2019 11:59 p.m.

Work individually on this assignment.

Problem 1. (3 pts. per part) Determine if the following statements are true or false and prove your answers. To prove a statement is true, specify the needed constants and show the definition holds for them.

  1. 2 lg n = O(sqrt(n))

  2. 4 n lg n = O(n2)

  3. n2 = O(n)

  4. 2 + 3 n + 2 n2/2 = Θ(n2).

  5. lg 2n is Θ(n2).

Problem 2. (4 pts.) Assume that f(n) = O(g(n)). Can g(n) = O(f(n))? Are there cases where g(n) is not O(f(n))? Prove your answers (give examples for the possible cases as part of your proofs, and argue the result is true for your example).

Problem 3. (5 pts. for each part) Solve the following recurrences using the recursion tree method. For full credit, show your work. I realize that some of you will be able to write the answer by inspection after the next lecture and recitation, but I want to see that you understand where the answers come from.

Hint: See p.~1147 of the text on summing geometric series and recall some logarithm properties in order to get a closed-form solution in terms of a polynomial in n for part (a).

(a) T(n) = 5 T(n/3) + 1, where T(1) = 1

(b) T(n) = 4 T(n/4) + n, where T(1) = 0
Problem 4. (5 pts.) Using induction, prove that your answer to problem 3(b) is correct when n is a power of 4. You may work exactly or in terms of big-O.

Problem 5. (4 pts.) For the following code fragment, determine the running time for a call of PrintSquares(n). Show how you got your answer by indicating a critical step and arguing exactly how many critical steps occur as a function of n. State your answer in big-Θ notation in terms of n:
// Program to compute the squares from 1 to m

PrintSquares(m)
  for j = 1 to m
      result = Square(j)
      print result

// Function to compute kth square

Square(k)
  total = 0
  for i = 0 to k-1
      total = total + 2*i + 1
  return total