0

I am implementing a hash table in java and I have to define the hash function. I am following the MAD Form.

I read in internet:

The MAD method: h2(y) = [(ay + b) mod p] mod N, where N is the size of the hash table, p is a prime number larger than N, and a and b are integers chosen at random from the interval [0, p-1], with a > 0.

Which number should be P? How larger than N?

Zabuzard
  • 25,064
  • 8
  • 58
  • 82
MrScf
  • 2,407
  • 5
  • 27
  • 40
  • 1
    it really doesn't matter. most of the library use 31. but the catch is the bigger the better. – roottraveller Jun 15 '19 at 08:57
  • 1
    Also see [Why is it best to use a prime number as a mod in a hashing function?](https://cs.stackexchange.com/questions/11029/why-is-it-best-to-use-a-prime-number-as-a-mod-in-a-hashing-function) and [Wikipedia: Universal hashing](https://en.wikipedia.org/wiki/Universal_hashing) – Zabuzard Jun 15 '19 at 08:57
  • Try [Wolfram Alpha nextprime(N)](https://www.wolframalpha.com/input/?i=NextPrime%5Bn%5D) – President James K. Polk Jun 15 '19 at 14:21

0 Answers0