0

Consider inserting the keys 10, 22, 31, 9 , 15, 28, 62, 88 in to a hash table of length m = 11 using open addressing with the hash function h(k) = k mod m. Illustrate the result of inserting these keys using double hashing with h2(k) = 1 + (k mod(m-1)).

Following is my approach.

0 -> 22 , Since 22 mod 11 = 0
1 ->
2 ->
3 ->
4 ->
5 ->
6 ->
7 ->
8 ->
9 -> 31 , Since 31 mod 11 = 9
10 -> 10 , Since 10 mod 11 = 10

Ok the problem comes when try to put the key 9 in to the hash table.

h(9) = 9 mod 11, which is 9. I can't put 9 since 9 already gone. Then I try for the double hash function given h2(9) = 1 + (9 mod (11-1)) , which is 10 and it's gone again. So still I can't put 9 in to the hash table. What should I do in such scenarios.

4

2 に答える 2

0

最後に、wikiの説明を使用して答えを見つけることができました。http://en.wikipedia.org/wiki/Double_hashing

h(9) = 9 mod 11、つまり 9 です。

h2(9) = 1 + (9 mod (11-1)) は 10 です。

したがって、キーは (9 + 10) mod 11、つまり 8 である必要があります。

それから

8 -> 9

于 2012-05-11T06:13:25.777 に答える