gpt4 book ai didi

algorithm - 哈希表 quadrtc。试探

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:21:30 25 4
gpt4 key购买 nike

需要一个例子

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

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

f(i)= i^2

如果有任何帮助,我将不胜感激。

最佳答案

对于大小为 7 的 table ,假设位置 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
...

关于algorithm - 哈希表 quadrtc。试探,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33376002/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com