HW1

CS 350
Due 1/23 before class starts

Problem 1

List the functions below from lowest order of growth to highest. If any two or more are the same, indicate which.

n\sqrt{n} mm 2n2^n
nlognn \log n nn3+7n5n - n^3 + 7n^5 k2+logkk^2 + \log k
m2m^2 n3n^3 logn\log n
n13+lognn^{\frac{1}{3}} + \log n (logn)2(\log n)^2 n!n!
lnm\ln m nlogn\frac{n}{\log n} loglogk\log \log k
(13)n(\frac{1}{3})^n (32)n(\frac{3}{2})^n 6

Problem 2

Prove that for any positive integer constants aa and bb where b>0b>0
(n+a)bΘ(nb)(n+a)^b \in \Theta(n^b)

(Hint: show that (n+a)bΩ(nb)(n+a)^b \in \Omega(n^b) and that (n+a)bO(nb)(n+a)^b \in \mathcal{O}(n^b) providing values for c1c_1, c2c_2, and n0n_0.)


Problem 3

(From textbook 2.2 ex. 2) Use the informal definitions of O\mathcal{O}, Θ\Theta, and Ω\Omega to determine whether the following assertions are true or false.

  1. n(n+1)/2O(n3)n(n+1)/2 \in \mathcal{O}(n^3)
  2. n(n+1)/2O(n2)n(n+1)/2 \in \mathcal{O}(n^2)
  3. n(n+1)/2Θ(n3)n(n+1)/2 \in \Theta(n^3)
  4. n(n+1)/2Ω(n)n(n+1)/2 \in \Omega(n)

Problem 4

(From textbook 2.3 ex. 4) Consider the following algorithm:

Mystery Algorithm
Input: A non-negative integer nn
Output: ?

  S <- 0
  for i <- 1 to n do
    S <- S + i * i
  return S
  1. What does this algorithm compute?
  2. What is its basic operation?
  3. How many times is the basic operation executed?
  4. What is the efficiency class of this algorithm?
  5. Suggest an improvement, or a better algorithm altogether, and indicate its efficiency class. If you cannot do it, try to prove that, in fact, it cannot be done.

Problem 5

(From textbook 2.3 ex. 1) Compute the following sums.

  1. 1+3+5+7+...+9991+3+5+7+ ... + 999
  2. 2+4+8+16+...+10242+4+8+16+ ... +1024
  3. i=3n+11\sum_{i=3}^{n+1}1
  4. i=3n+1i\sum_{i=3}^{n+1}i
  5. i=0n1i(i+1)\sum_{i=0}^{n-1}i(i+1)
  6. j=1n3j+1\sum_{j=1}^{n}3^{j+1}
  7. i=1nj=1nij\sum_{i=1}^{n}\sum_{j=1}^{n}ij
  8. i=1n1i(i+1)\sum_{i=1}^{n}\frac{1}{i(i+1)}

Problem 6

(From textbook 2.4 ex. 1) Solve the following recurrence relations.

  1. x(n)=x(n1)+5x(n) = x(n-1) + 5 for n>1n >1, x(1)=0x(1)=0
  2. x(n)=3x(n1)x(n) = 3x(n-1) for n>1n>1, x(1)=4x(1) = 4
  3. x(n)=x(n1)+nx(n) = x(n-1) + n for n>0n>0, x(0)=0x(0) =0
  4. x(n)=x(n/2)+nx(n) = x(n/2) + n for n>1n>1, x(1)=1x(1) =1 (solve for n=2kn = 2^k)
  5. x(n)=x(n/3)+1x(n) = x(n/3) + 1 for n>1n >1, x(1)=1x(1)=1 (solve for n=3kn = 3^k)