Homework Assignment 5


Due: Mar. 2 before class starts


Assignment

  1. (50 points) What is the best, average and worst-case asymptotic time complexity for performing n (correct) remove() operations on a map that initially contains 2n entries and implemented with: Please write statements and proofs for each. Your proofs can reference each other if the arguments are identical.
  2. (50 points) Suppose that each row of an n × n array A consists of 1's and 0's such that, in any row of A, all the 1's come before any 0's in that row. Assuming A is already in memory, describe a method running in O(n log n) time (not O(n2) time) for counting the number of 1's in A.
    1. Provide and explain pseudocode
    2. Statement and proof of time complexity
    3. Statement and proof of memory complexity
  3. Bonus. (10 points) The quadratic probing strategy has a clustering problem that relates to the way it looks for open slots when a collision occurs. Namely, when a collision occurs at bucket h(k), we check A[(h(k) + i2) mod N], for i = 1,2,...,N - 1.
    1. Show that i2 mod N will assume at most (N + 1)/2 distinct values, for N prime, as i ranges from 1 to N - 1. As a part of this justification, note that i2 mod N = (N - i)2 mod N for all i.
    2. A better strategy is to choose a prime N, such that N mod 4 = 3 and then to check the buckets A[(h(k) ± i2) mod N] as i ranges from 1 to (N - 1)/2, alternating between plus and minus. Show that this alternate version is guaranteed to check every bucket in A.