Would you get the same hash map through the double hashing algorithm & the quadratic hashing algorithm?

85 views Asked by At

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?

1

There are 1 answers

0
Jim Mischel On

If j is a constant, then no. There is no constant, j that will satisfy the equality:

13 - k mod 13 == (k mod 29 + (j * j)) mod 29

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 29 can generate values in the range 0 to 28, the answer is no.