数组/列表vs字典(为什么我们有它们在第一个地方) [英] Array/list vs Dictionary (why we have them at first place)
问题描述
数组提供了一组顺序数据的随机访问。字典(或关联数组)提供从一组键到一组值的映射。
我相信你正在比较苹果和橘子 - 它们提供两个完全不同的目的,都是有用的数据结构。
大多数时候,类似字典的类型被构建为哈希表 - 这种类型是非常,因为它提供了非常快的查询平均(取决于哈希算法)。
To me they are both same and that is why i am wondering why we have dictionary data structure when we can do everything with arrays/list? What is so fancy in dictionaries?
Arrays provide random access of a sequential set of data. Dictionaries (or associative arrays) provide a map from a set of keys to a set of values.
I believe you are comparing apples and oranges - they serve two completely different purposes and are both useful data structures.
Most of the time a dictionary-like type is built as a hash table - this type is very useful as it provides very fast lookups on average (depending on the quality of the hashing algorithm).
这篇关于数组/列表vs字典(为什么我们有它们在第一个地方)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!