CSCI 3104 - Algorithms - Spring 2011

Problem Set #1

Due: Fri, Jan 21st



1. In each of the following situations, indicate whether f = O(g), or f = Ω(g), or both (in which case f = Θ(g)).
(a) f(n) = n1.01, g(n) = n
(b) f(n) = lg n, g(n) = ln n
(c) f(n) = 2n, g(n) = 3n

2. The text spends a lot of time talking about fib(200). Compute this number exactly using Python. Submit your code listing along with the value of fib(200), on paper.

3. Look up the "golden ratio" online. Call this number φ. Using your favorite multi-precision calculator (python works again), compute φ200/sqrt(5) rounded to the nearest integer. Compare the efficiency of this method to the method of problem 2. (Think about how Python must be internally computing its exponentiation function.)

4. Consider the following Python function:

def find(a, target):
    x = 0
    y = len(a)
    while x < y:
        m = (x+y)/2
        if a[m] < target:
            x = m+1
        elif a[m] > target: 
            y = m
        else:
            return m
    return -1
Suppose list a has n elements and is sorted. Using Θ() notation, what is the best case running time as function of n? Using Θ() notation, what is the worst case running time as function of n?

5. Modify the find function from problem 4 by changing the 5th line from m = (x+y)/2 to m = (2*x+y)/3; now answer the same questions given in problem 4.