Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please explain your answer with at least 50 words :-) You are implementing a has

ID: 3889880 • Letter: P

Question

Please explain your answer with at least 50 words :-)

You are implementing a hash table. The hash table may need to grow and shrink as the number of stored keys varies. You have a hashcode function that uniformly hashes keys to positive 32-bit integers. The table itself will use a smaller array of approximate size M. Which of the following is best choice for the hash function that takes the hashcode to produce a value between O and P-1 where P is close to M? Either Modulo P where P is the power of 2 closest to M Modulo P where P is a prime closest to M Neither

Explanation / Answer

ANSWER : Modulo P where P is the power of 2 closest to M

Explanation :

Ex:

A = 1 = (001)2 , (base 2)

B = 3 = (011)2

      A & B = (001)2 & (011)2= (001)2 = 1