An algorithm has to store several keys generated by an adversary in a hash table. The adversary is malicious who tries to maximize the number of collisions. Let be the number of keys, be the number of slots in the hash table, and .
Which one of the following is the best hashing strategy to counteract the adversary?
View worked solution
Answer: C
To counteract a malicious adversary who tries to maximize collisions, we must avoid using any fixed, deterministic hash function.
Why deterministic methods fail:
- If we use a fixed hash function (such as the Division method in Option A or the Multiplication method in Option B), the adversary can easily compute the hash values for a large set of keys.
- Since the number of keys is greater than the number of slots (), the adversary can select keys that all map to the exact same slot, resulting in a worst-case search time of .
Why Universal Hashing succeeds:
- In Universal Hashing (Option C), the hash function is selected at random at runtime from a carefully designed family of hash functions.
- Because the specific hash function is chosen randomly and is unknown to the adversary beforehand, the adversary cannot choose a set of keys that guarantees worst-case collisions.
- The expected number of collisions for any subset of keys is mathematically bounded to at most , ensuring optimal average-case performance regardless of the inputs chosen by the adversary.
Therefore, Universal hashing method is the best strategy to counteract the adversary.
Free practice · Your answers on this page are not saved.
