为什么最坏情况下hast table的时间复杂度是O(n)
Why the worst case of hast table's time complexity is O(n)
我看过维基百科,因为访问 hast table 只是简单地通过数组索引,如 hast_table[index]
,所以它应该是 O(1)
,为什么 hast 的最坏情况 table的时间复杂度是O(n)。最坏的情况是什么?
使用侧链的容量为 1 的哈希 table 退化为链表,导致查找需要在 table 的单个存储桶中进行线性搜索。
https://en.wikipedia.org/wiki/Hash_table#Separate_chaining_with_linked_lists
我看过维基百科,因为访问 hast table 只是简单地通过数组索引,如 hast_table[index]
,所以它应该是 O(1)
,为什么 hast 的最坏情况 table的时间复杂度是O(n)。最坏的情况是什么?
使用侧链的容量为 1 的哈希 table 退化为链表,导致查找需要在 table 的单个存储桶中进行线性搜索。
https://en.wikipedia.org/wiki/Hash_table#Separate_chaining_with_linked_lists