Pergunta

I have a hash table of size 11, implemented as an array. I am attempting to use the double hash technique; I have already done most of my numbers. My hashing function is as follows:

h1 = key mod 11
h2 = 3*key mod 4

This gives me h(k,i) = k mod 11 + i(k * 3 mod 4) where i = 0, 1, 2, 3, ...

I already have slots 0, 1, 4, 8, 9, and 10 filled in. I am trying to insert 19. This is my result for hashing 19:

1st time: 8  <-- collision 
2nd time: 9  <-- collision 
3rd time: 10 <-- collision 
4th time: 11 <--- well there is no index 11 table ends with index 10

What should I do?

Also, when they say, "Let the table have 11 slots," does that mean that the hash table has available slots from 0 to 10?

Foi útil?

Solução

This change will fix the wrong hash table index calculation:

h(k,i) = (key + i*(key*3 mod 4)) mod 11
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top