为什么在众多Python字典操作中,dict频繁遭遇O(n)最坏时间复杂度?
- 内容介绍
- 文章标签
- 相关推荐
本文共计419个文字,预计阅读时间需要2分钟。
How does dict implement linear-time lookup for collisions? I assume it uses a hash table backed by a list.
Howexactlyisdictimplementedthatithasalineartimelookupforcollisions?IwouldassumethatHow exactly is dict implemented that it has a linear time lookup for collisions? I would assume that it is implemented as a hashtable backed by a list. I would presume that a better implementation would be O(log(n)) for various operations, using a tree to back the table instead. Is there some magic happening behind the scenes to keep the constant time lookups alive for as long as possible?
dict究竟是如何实现的,它具有线性时间查找冲突?我认为它是作为由列表支持的哈希表实现的。我认为对于各种操作,更好的实现将是O(log(n)),而使用树来代替表。
本文共计419个文字,预计阅读时间需要2分钟。
How does dict implement linear-time lookup for collisions? I assume it uses a hash table backed by a list.
Howexactlyisdictimplementedthatithasalineartimelookupforcollisions?IwouldassumethatHow exactly is dict implemented that it has a linear time lookup for collisions? I would assume that it is implemented as a hashtable backed by a list. I would presume that a better implementation would be O(log(n)) for various operations, using a tree to back the table instead. Is there some magic happening behind the scenes to keep the constant time lookups alive for as long as possible?
dict究竟是如何实现的,它具有线性时间查找冲突?我认为它是作为由列表支持的哈希表实现的。我认为对于各种操作,更好的实现将是O(log(n)),而使用树来代替表。

