[英]Average cost of successful search in hash table in chaining
I have searched every where for this but I can't understand why is it O(1+a/2) where a is the load factor. 我在每个地方都进行了搜索,但我不明白为什么它是O(1 + a / 2),其中a是负载系数。 Can some one explain this step by step. 有人可以逐步解释这一点。
Let the number of elements in your hash table be n
. 令哈希表中的元素数为n
。
It means there are n/a
total number of cells (/lines) in the hash table, each holds a list of elements. 这意味着哈希表中共有n/a
单元格(/行),每个单元格包含一个元素列表。 This is the definition of load factor. 这是负载系数的定义。
So, the expected number of elements assossiated to each such cell is n/(n/a) = a
. 因此,与每个此类像元关联的元素的预期数量为n/(n/a) = a
。
A linear search in an unsorted list needs to traverse half of the elements until it finds the correct one on average (and we assume it is a succesful search), so it needs to traverse a/2
elements. 在未排序列表中的线性搜索需要遍历一半的元素,直到平均找到正确的元素为止(并且我们假设这是一次成功的搜索),因此它需要遍历a/2
元素。
The 1
factor comes from accessing the correct list in the hash table itself. 1
因素来自访问哈希表本身中的正确列表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.