Skip to content
Official PYQ · 2023

GATE CS 2023 Q10 — Searching, Sorting, Hashing

Explain with AI

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 kk be the number of keys, mm be the number of slots in the hash table, and k>mk>m.

Which one of the following is the best hashing strategy to counteract the adversary?

Choose one option
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 kk is greater than the number of slots mm (k>mk > m), the adversary can select kk keys that all map to the exact same slot, resulting in a worst-case search time of Θ(k)\Theta(k).

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 kk keys is mathematically bounded to at most km\frac{k}{m}, 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.

Published
Report a correction
Keep exploringMore Searching, Sorting, Hashing questions