CS 212 — Homework Three

A little complexity

Due: 20 February 2013, 11:59p

Worth: 45 points

  1. [5 pts] Why do we not use the best-case performance of an algorithm to determine complexity?
  2. [5 pts] Given the functions f(n) = n3 and g(n) = 2nlgn, is f(n) = O(g(n)), Θ(g(n)), or Ω(g(n))? Prove it using the definitions provided in class
  3. [25 pts] We have looked at two different implementations of the List interface, the ArrayList and the LinkedList. We know that the LinkedList takes more space, and that the ArrayList occasionally needs to be resized. Baring these two factors, we need to consider what would drive the adoption of one or the other of these. For each method (except for the iterator methods), state the complexity of each implementation and describe why.
  4. [5 pts] Prove that n+2lg(n) = O(n).
  5. [5 pts] Given the following method, what is its complexity? I would like you to first find the actual complexity and then simplify it to one of our primary classes (with proof).
  6. 
    public static reduce(int n){
        int result = 0;
        while (n >1){
             n = n/2;
             result = result  +1;
        }
        return result;
    }
    

    Turning the assignment in...

    Please type your answers up and convert the file to a PDF. Name the PDF cs211_pid_hw3.pdf, where pid is your Mount Holyoke email account name and submit it on ella.


Last modified: Fri Feb 15 12:58:56 EST 2013