字典和哈希表之间的真正区别是什么? [英] What is the true difference between a dictionary and a hash table?
本文介绍了字典和哈希表之间的真正区别是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
字典是将键映射到值的一般概念。有很多方法来实现这样的映射。
散列表是实现字典的一种特定方式。
除了哈希表外,实现字典的另一种常见方法是红黑树。
每种方法都有自己的优缺点。红黑树总是可以在O(日志N)中执行查找。散列表可以在O(1)时间内执行查找,尽管可能会根据输入降级为O(N)。
I've always used dictionaries. I write in Python.
解决方案
A dictionary is a general concept that maps keys to values. There are many ways to implement such a mapping.
A hashtable is a specific way to implement a dictionary.
Besides hashtables, another common way to implement dictionaries is red-black trees.
Each method has it's own pros and cons. A red-black tree can always perform a lookup in O(log N). A hashtable can perform a lookup in O(1) time although that can degrade to O(N) depending on the input.
这篇关于字典和哈希表之间的真正区别是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文