memory management - Hashing google interview -


why can't powers of 2 or power's of 10 or prime numbers hashing functions? if want store overflow records in hash function, why aren't selection of hashing functions?

suppose hash function returns 32-bit unsigned result. suppose choose modulus of 4096. is, effectively: index = hash & 0xfff -- so, throw away top 20 bits of hash value. now, if hash really good, , bottom 12 bits rest, that's not problem. however, if hash pretty on 32 bits, bottom 12 bits suspect (they might, example, more influenced last characters of string)... may regret discarding top 20. in case, if choose odd modulus, index = hash % modulus result depends on 32 bits of hash.

so, more generally, if hash calculated modulo m, , index taken hash % n, want m , n co-prime.

if m 2^m (as is), n=10^n poor choice, because bottom n bits of resulting index straight copy of bottom n bits of hash.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -