600.226 Data Structures -- Spring 2013
Homework #2 -- 54 Points Total
Due by 3pm on Friday, 2/8

The purpose of this assignment is to gain experience with the analysis tools we will be using throughout the semester. Because there is alot of math involved, you only need to submit this assignment on paper, in class on Friday. It can be hand-written if you prefer. However, make sure that whatever you submit is completely legible! Show work for partial credit. If you would like to submit it on Blackboard, that is also an option, but you MUST submit a hard-copy in class regardless.

You may need to brush up on some math skills, particularly regarding laws of exponents and logs, and also proof techniques. Review the classnotes from days 2-4 for details. The Weiss text, Chapter 2 contains formal definitions of the various asymptotic complexities that we are working with, and a math review. Wikipedia also has a very thorough explanation. The Sedgewick and Wayne text takes a slightly different approach in Chapter 1.4.

  1. [16 pts] For each of the functions listed below, figure out its growth rate (simplify first!). Then rank the functions in growth rate order, starting with the slowest growth rate (ie, those resulting in a fast runtime), and ending with the fastest growth rate (worst runtime). If two functions have the same asymptotic complexity, then rank them based on the original expressions (including constants).
     
    Function    big Θ( )      rank   
    (log N/4)3   
    (N2-4) / (N+2)  
    (N + log N)3   
    3 log N2   
    (2N)2 + log N  
    N2 log 16  
    2N log log N   
    4N2 + N(10 + log N)   
     
  2. [14 pts] For each of the following code fragments, derive the Θ time complexity (tight bound) as a function of N. Remember, this means it must be big O and Ω of the function, bounded above and below. You must show all work, including approximate operation counts. For partial credit, give the best O and Ω bounds you can figure out.
     a) [2]
        sum = 0;
        for ( i = 0; i < 2*N; i+=4)
            sum += i;
    
     b) [4]
        sum = 0;
        for ( i = N; i > 0; i /= 2)
            for ( j = 0; j < i; j ++)
                sum++;
    
     c) [4]
        sum = 0;
        for ( i = 0; i < 3*N; i++)
            for ( j = 0; j < 5; j++)
                for ( k = i; k > 1; k--)
                    sum++;
    
     d) [4]
        sum = 0;
        s = keyboard.nextLine(); // assume keyboard is an initialized Scanner
        N = s.length();
        v = "aeiou";
        for ( i=0; i < v.length(); i++)
            if ( s.indexOf(v.charAt(i)) >= 0)
                 sum++;
    
  3. [4 pts (2 each)] For each of these problems, use the growth factor between the initial problem size and the new problem size to estimate the new running time.
    1. Suppose you have a quadratic time algorithm that takes 10ms to run when the input size is 25. How long do you think it will take to run for an input of size 100?
    2. Suppose you have a θ(2N) algorithm that takes 10ms to run when the input size is 25. How long do you think it will take to run for an input of size 100?
  4.  
  5. [10 pts] Suppose we know that T1(N) = O(f(N)) and T2(N) = Θ(g(N)). For each statement below, either prove that it is true by finding appropriate c and n values, or show that it is false by giving a counterexample.
    	T1(N) + T2(N) = Ω(f(N) + g(N))
    
    	T1(N) * T2(N) = O(f(N) * g(N))
    
    
  6. [4 pt] Explain how to raise some number x to the 64th power using only 6 multiplications.
  7.  
  8. [6 pt] Derive a simplified closed form version of ∑ (i=0, N-1) (32i - 4i + 6), showing all work. You'll need to separate terms, simplify, apply summation rules, and recombine.
         N-1     2i
         SUM  (3   -  4i  +  6)  = 
         i=0