【发布时间】:2021-04-06 09:41:31
【问题描述】:
我目前正在阅读 CLRS 书籍并查看其中如何定义哈希表,在谈到开放哈希和使用链接解决冲突时,有一段文字如下:
If the hash table supports deletion, then its linked lists should be doubly linked
so that we can delete an item quickly. If the lists were only singly linked, then to
delete element x, we would first have to find x in the list T[h(x.key)] so that we
could update the next attribute of x’s predecessor. With singly linked lists, both
deletion and searching would have the same asymptotic running times.)
我不明白为什么会出现这种情况(或者更具体地说是如何),这不是一个问题,即当你知道元素加倍时为什么从链表中删除它会更快链表,我想我应该说清楚...
这与实际知道位置的方式有关,因此双向链表可以产生这种差异,因为查看哈希删除伪代码(如下),密钥用于生成导致正确的哈希可以找到链表的数组索引,但如何准确地将其转换为项目链表中的实际位置?
CHAINED-HASH-DELETE(T, x)
1 delete x from the list T[h(x.key)]
在我看来,仅对链接列表的键进行哈希处理,因此在任何一种情况下,仍需要搜索列表以找到当前正在删除的实际值?
我确定有一个简单的答案,但我不清楚!
【问题讨论】:
标签: linked-list hashtable clrs