Suppose for a Double Hashing Algorithm,
h(k) = k mod 29 & h'(k) = 13 - k mod 13
and for a Quadratic Hashing Algorithm
h(k) = k mod 29 & h'(k) = h(k) + (j * j)
Where the size of the array is the same (ex. 29 for both algorithms).
Would you be able to construct identical hash tables using both these algorithms separately?
If you were to output each individual key (with their respective values) from a bucket array, would the keys (from both algorithms) be in the same spot in the bucket array? Or would the keys be sorted differently?
If
jis a constant, then no. There is no constant,jthat will satisfy the equality:For all values of
k.By the way,
13 - (k mod 13)is a terrible secondary hashing function. That limits your secondary hash to the range 0 through 12. You'll end up with many more keys in the first 13 buckets than in buckets 13 through 28.Come to think of it, because
13 - (k mod 13)limits results to values 0 through 12, and(k mod 29 + (j * j)) mod 29can generate values in the range 0 to 28, the answer is no.