CSCE 221: Data Structures and Algorithms

Sections: 507, 508, 509
Fall 2015



Homework 5


Due Date: Oct. 9th (before class)


Assignment

  1. Similar to R9.3 (Pg. 417)

    What is the best, average and worst-case asymptotic running time for performing n (correct) erase() operations on a map that initially contains 2n entries and implemented with:

    • unordered list
    • direct address table
    • ordered search table
    • hash with chaining
    • hash with linear probing
    • hash with double hashing

    Please state justifications, but you can reduce to one explanation if more that one case coincides on complexity/justification.

  2. C9.11 (Pg. 419)

    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(nlogn) time (not O(n2) time!) for counting the number of 1's in A. Provide the pseudocode (can utilize subroutines if discussed in the book chapter -- just reference them), correctness (code explanation), and justification for the time complexity.


Bonus

    C9.9 (Pg. 419)

    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)+ f(j)) mod N], for f(j) = j2, using j = 1,2,...,N - 1.

    1. Show that f(j) mod N will assume at most (N + 1)/2 distinct values, for N prime, as j ranges from 1 to N - 1. As a part of this justification, note that f(R) = f(N - R) for all R.
    2. A better strategy is to choose a prime N, such that N is congruent to 3 modulo 4 and then to check the buckets A[(h(k) ± j2) mod N] as j ranges from 1 to (N - 1)/2, alternating between addition and subtraction. Show that this alternate type of quadratic probing is guaranteed to check every bucket in A.


Grading Rubric

Each homework composes 2% of your final grade. Each homework will be graded out of 100 possible points. In any problem asking you to design an algorithm please also provide proper pseudocode (mathematical notation), complexity analysis (both space and time), and brief justification of complexity and correctness.

All assignments must be turned in with a signed coverpage. If no coverpage is provided, the assignment will not be graded.

If there are any discrepancies in grades please see Jory Denny during his office hours (not the TA or Grader).