0

需要一个例子

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

我在表大小上尝试了一些不同的输入,函数为: h of i (x) = (hash(x) + f(i)) mod table size

f(i)= i^2

我会很感激任何帮助谢谢。

4

1 回答 1

1

对于大小为 7 的表格,假设点 0、1、2、4 被占用,3、5、6 是空闲的。现在尝试在 hash(x) = 0 的地方插入一个 x。

示例:让我们采用 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
...
于 2015-10-27T19:17:15.377 回答