PHP阵列的时间/空间复杂度 [英] Time/Space complexity of PHP Array

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

问题描述

有没有一种方法或寻找在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.net

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.net

从我可以告诉它似乎它有一个地图的复杂性一般

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的<一个href=\"http://www.google.com/$c$csearch/p?hl=en#EKZaOgYQHwo/unstable/sources/php-5.1.4.tar.bz2%7COdM6HPk4UX4/php-5.1.4/ext/standard/array.c&q=array%20lang%3ac%20package%3aphp\"相对=nofollow>实施阵列这里的

If you have time, you can actually check out PHP's implementation of array here

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

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