简体   繁体   English

使用单独的链计算探针的平均数量

[英]Calculate average number of probes with Separate chaining

Suppose we are given the hash table below: 假设我们得到下面的哈希表: 在此处输入图片说明

where the collision resolution method is Separate chaining. 其中冲突解决方法是“单独链接”。 I am trying to calculate the average number of probes to find an empty slot. 我正在尝试计算探查空槽的平均数量。 According to my lecture slides the average is 1.77, but I keep getting a different answer. 根据我的演讲幻灯片,平均值为1.77,但我一直得到不同的答案。 Any assistance would be much appreciated. 任何帮助将不胜感激。

So, it works like this: The idea is if you hit an empty bucket, then you are done. 因此,它的工作方式如下:想法是,如果您打了一个空桶,那就完成了。 But if you hit a non-empty bucket, you need to traverse the chain and find a empty slot at the end of the chain. 但是,如果您碰到一个非空的存储桶,则需要遍历链,并在链的末尾找到一个空插槽。

So the resulting average probe hits is: 因此,产生的平均探测命中为:

(8 empty slots * (1 probe/empty slot)) / 13 total slots
+
(2 slots with one element *(2 probes for slot with one element) /13 total slots
+
(2 slots with two elements *(3 probes for slot with two elements) /13 total slots
+
(1 slots with four elements *(5 probes for slot with four elements) /13 total slots

= 8/13 + 4/13 + 6/13 + 5/13

= 23/13

= 1.77

Not sure why you want to find out average probes for empty slot in Separate Chaining method. 不确定为什么要使用“单独链接”方法找出空插槽的平均探测值。 It would be of concern in Open Addressing method. 在“开放寻址”方法中将引起关注。 And it would depend on nature of your data ie what is probability of getting hash-code%12 among already occupied index locations. 这将取决于您数据的性质,即在已被占用的索引位置中获得哈希码%12的概率是多少。

If you are just interested in metrics for given array: 如果您只对给定数组的指标感兴趣:

There are 10 elements in array of size 13. So: 大小为13的数组中有10个元素。因此:

Minimum probability of finding empty location is 3/13 - when each 10 elements lands in different bucket 找到空位置的最小概率是3/13-当每10个元素落在不同的存储桶中时

Maximum probability of finding empty location is 12/13 (if all 10 elements land in one bucket) 找到空位置的最大概率为12/13(如果所有10个元素都落在一个存储桶中)

For given data it is 8/13 对于给定的数据是8/13

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM