有没有一种方法或寻找在PHP比手工计算它的其他数组实现的时间和空间复杂的资源?
Is there a way or a resource for finding the time and space complexity of the Array implementation in PHP other than calculating it by hand?
在PHP中的数组实际上是一个有序图。图是一种把值keys的类型。这种类型在很多方面做了优化;它可以被视为一个阵列,列表(矢量),哈希表(映射的实现),字典,集合,栈,队列和可能更多。如数组值可以是其它的阵列,树木和多维数组也是可能的。 - php
An array in PHP is actually an ordered map. A map is a type that associates values to keys. This type is optimized for several different uses; it can be treated as an array, list (vector), hash table (an implementation of a map), dictionary, collection, stack, queue, and probably more. As array values can be other arrays, trees and multidimensional arrays are also possible. - php
从我可以告诉它似乎它有一个地图的复杂性一般
From what I can tell it would seem that it has the general complexity of a map
推荐答案由于它的作用就像一个哈希表,你会访问一个元素时有 O(1)时间由关键
Because it acts like a hash table, you will have O(1) time when accessing an element by a key.
如果您通过数组循环,自然你就会拥有 O(N)的时间。
If you are looping through the array, naturally you will have O(n) time.
如果你有时间,你其实可以看看PHP的实施阵列这里的
If you have time, you can actually check out PHP's implementation of array here
更多推荐
PHP阵列的时间/空间复杂度
发布评论