1. Name: Nguyen Thi Nha Trang
ID: IT060052
ASSIGNMENT
Why the size of the array of a hash table should be a prime number.
We have:
Arrayindex = hugeNumber % arraySize
Where:
• Arrayindex is the array index where the object is stored.
• hugeNumber is the hash value of the object to be stored.
• arraySize is the length of the array of the hash table.
The reason why array’s size of a hash table should be a prime number is that it can help
to reduce the collisions.
To make it easier to understand, lets suppose that if the array’s size is not a prime
number, then the remainder of the modulo operation will return 0 for all hash values
which are divisible by the array’s size. This will cause collisions which would force the
hash table to switch on the collision resolution logic which is very complex. It also will
make the hash table to call Equals function to all previously stored objects with the same
hash value to find out if the same object was already stored. Therefore, the array’s size
should be a prime number to help avoiding the collisions after the operating of the
modulo function.