阵列访问复杂性 [英] Array Access Complexity

查看:129
本文介绍了阵列访问复杂性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java中,我需要在代码中多次访问 array1 [index]

In Java supppose I need to access array1[index] many times in the code.

即使对于非常大的数组,我是否可以假设每个单一数组访问需要恒定的时间?

这可以在语言或底层架构之间有所不同吗?

Even for extremely large arrays, can I assume each single array access takes constant time?
Can this differ between languages or underlying architecture?

推荐答案


对于array1大小为N的大值,我可以假设每个单一数组访问(array1 [index]需要一段时间吗?

For large values of array1 size N can I assume each single array access (array1[index]) takes constant time?

在Java中,是的。同样在C,C ++和C#中,禁止OS级别的内存分页问题,​​这些问题可能超出了范围。

In Java, yes. Also in C, C++, and C#, barring OS-level memory paging issues that are presumably out of scope.


此访问时间是否依赖于语言(java vs C ++)或底层架构?

Does this access time depend on language( java vs C++) or the underlying architecture ?

如果有问题的语言称为数组,那么它可以在通常的连续内存块意义上,确实存在阵列。 (JavaScript做到了;它的数组 [] )输入实际上是一个地图; PHP使用术语数组作为关联数组的简写[例如,map]。)所以对于给定的环境/语言,值得检查该术语是否被滥用或松散使用。

It can, if the language in question calls things "arrays" that aren't really arrays in the usual "contiguous block of memory" sense. (JavaScript does that; its Array ([]) type is really a map; PHP uses the term "array" as shorthand for "associative array" [e.g., map].) So for a given environment/language, it's worth checking that the term isn't being misused or used loosely.

这篇关于阵列访问复杂性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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