哈希表quadrtc。探测

时间:2015-10-27 18:38:29

标签: algorithm hashtable quadratic-probing

需要一个例子

我需要给出表格的大小和我试图插入的元素,因为在表格超过半满后因碰撞而无法插入。

我在表大小上尝试了几个不同的输入,功能如下: h of i(x)=(hash(x)+ f(i))mod表大小

f(i)= i ^ 2

感谢任何帮助,谢谢。

1 个答案:

答案 0 :(得分:1)

对于大小为7的表,假设取点0,1,2,4,3,5,6是自由的。 现在尝试插入一个x,其中hash(x)= 0。

示例:let take hash(x)= x%7。

Insert 0: hash(0) = 0, this slot is free so insert 0 into slot 0
Insert 1: hash(1) = 1, this slot is free so insert 1 into slot 1
Insert 2: hash(2) = 2, this slot is free so insert 2 into slot 2
Insert 4: hash(4) = 4, this slot is free so insert 4 into slot 4
Insert 7: hash(7) = 0, slot 0 is already taken; start quadratic probing:
(0+1*1)%7 = 1 also taken
(0+2*2)%7 = 4 also taken
(0+3*3)%7 = 2 also taken
(0+4*4)%7 = 2 also taken
(0+5*5)%7 = 4 also taken
(0+6*6)%7 = 1 also taken
...