数组/列表vs字典(为什么我们有它们在第一个地方) [英] Array/list vs Dictionary (why we have them at first place)

查看:135
本文介绍了数组/列表vs字典(为什么我们有它们在第一个地方)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对我来说,他们都是一样的,所以我想知道为什么我们有字典数据结构,当我们可以用数组/列表做所有的事情?字典中有什么好看?

解决方案

数组提供了一组顺序数据的随机访问。字典(或关联数组)提供从一组键到一组值的映射。



我相信你正在比较苹果和橘子 - 它们提供两个完全不同的目的,都是有用的数据结构。



大多数时候,类似字典的类型被构建为哈希表 - 这种类型是非常,因为它提供了非常快的查询平均(取决于哈希算法)。


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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆