CMSI 282
Quiz 1

The test is open-everything with the sole limitation that you neither solicit nor give help while the exam is in progress.

Do any seven problems. Write the problem numbers of the problems you want me to grade in the left column below. Note that you get to pick one of them to count for all little less, just in case you feel a little unsure about your answer.

ProblemYou gotOut of
 
 
15
 
 
15
 
 
15
 
 
15
 
 
15
 
 
15
 
 
10
TOTAL
 
100
  1. Express (10 log2n)log10n in the form nc + f(n) where c is some positive constant and f is some function of n.
  2. Give both the best-case and worst-case time complexities of this function. (Use Θ-notation)

        public static long power(int x, int n) {
            return n == 0 ? 1
                : n % 2 == 0 ? power(x * x, n / 2)
                : x * power(x * x, n / 2)
        }
    
  3. An algorithm with complexity function T(n) = 2n can process a 30-element list on our PC in 512 seconds.
    1. How many days would it take to process a 40-element list?
    2. How many years would it take to process a 50-element list?
    3. If we ran the algorithm on a machine that was one billion times faster than our PC, how large of a list could we process in one day? (Note 1 day = 86400 seconds)
    4. If we needed a computer that could process 80 elements in a week, how much faster than our original PC does this computer need to be? (1 week = 604800 seconds)
  4. Sometimes you will see the complexity function Õ — it is defined like this:

    Õ(f(n)) = O(f(n)((log n)k))

    for some positive k. When an algorithm is known to have a complexity function in Õ(n3), for example, some people will just say instead that it is in O(n3+ε) — where, of course, ε is understood to be some arbitrarily small positive constant. Why is this okay?
  5. Consider the problem of sorting n k-bit numbers.
    1. When, if ever, is Counting Sort feasible? Explain.
    2. Give the best and worst case time complexities of Radix Sort.
    3. Give the best and worst case time complexities of Quick Sort.
    Answers should use Θ notation, where both n and k are variables in the complexity functions.
  6. Lehmann noticed that a number p is prime if and only if for every a less than p, a(p-1)/2 ≡ ± 1 (mod p), with at least one of the a's yielding -1 (In other words, they can't all yield 1). One of the Freshman wrote the following Java code to implement a probablistic Lehmann test, but there's a bug. What is the problem and how do you fix it?
    public static boolean isProbablePrime(BigInteger n, int certainty) {
        boolean negativeOneFound = false;
        BigInteger negativeOne = BigInteger.ZERO.subtract(BigInteger.ONE);
        BigInteger half = n.subtract(BigInteger.ONE).divide(new BigInteger("2"));
        for (int i = 0; i < certainty; i++) {
            BigInteger a;
            do
                a = new BigInteger(n.bitCount(), random);
            while (!(BigInteger.ONE.compareTo(a) <= 0 && a.compareTo(n) < 0));
            BigInteger x = a.modPow(half, n);
            if (x.equals(negativeOne)) {
                negativeOneFound = true;
            } else if (x.equals(BigInteger.ONE)) {
            } else {
                return false;
            }
        }
        return negativeOneFound;
    }
    
  7. Why, in practice, do people sign hashes of messages rather than whole messages?
  8. Generate the ciphertext for the message "woohoo" using the bifid algorithm with key "THEQUICKBROWNFOX". Lay out the key row by row, left to right within each row, as is the convention. Show the entire derivation.
  9. One of the seniors claims to be able to recover a DES-encrypted message with only 250 operations. If true, how big of an improvement is this over a brute-force attack? (You may answer in fractions or percentages.)