hashing, Array size greater than 10^6

How to hash numbers more than 10^6 or more??

Use modulo with a prime P. this might lead to 2 different numbers clashing for the same index which is referred as a “collision”, which can be overcome by using a double hash technique or making 2 separate hash tables with different primes as P.

Choosing primes will help. And then use modulo to restrict the hash value to less than a particular limit. You can deal with collisions using linked lists.

1 Like

You should choose a prime number in order to meet your requirement and handle the collision through chaining. Also if you want higher prime numbers , dynamically allot memory to array from heap using new operator in C++.