in Algorithms edited by
9,265 views
11 votes
11 votes

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

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

  1. Division method, i.e., use the hash function $h(k)=k \bmod m$.
  2. Multiplication method, i.e., use the hash function $h(k)=\lfloor m(k A-\lfloor k A\rfloor)\rfloor$, where $A$ is a carefully chosen constant.
  3. Universal hashing method.
  4. If $k$ is a prime number, use Division method. Otherwise, use Multiplication method.
in Algorithms edited by
by
9.3k views

3 Comments

Question was about how to minimize collision from an attacker with $n$ keys and $m$ slots.

Options were

A. modulo remainder

B. multiplication method

C. If m is prime, modulo, otherwise multiplication method.
1
1
D.using universal hashing function
1
1

@Sachin Mittal 1 Sir, please add the options.

1
1

3 Answers

10 votes
10 votes

Answer should be using universal hashing as it randomly chooses hashing function from range of function.
Reference:
CLRS 3rd version:chap:11, page no.265

3 votes
3 votes

Universal hashing refers to selecting a hash function at random from a family of hash functions with a certain mathematical property. This guarantees a low number of collisions in expectation, even if the data is chosen by an adversary. It implements uniform hashing.

ANSWER) C

https://en.wikipedia.org/wiki/Universal_hashing

 

0 votes
0 votes

(C.) Universal hashing method ,In universal hashing, at the beginning of the execution, we choose a hash function randomly from a carefully designed family of functions. This guarantees that no single input would result in the worst-case situation. Since the hash functions are random, the behavior would be different for for each execution which would yield average case performance on each input.