PHP阵列的时间/空间复杂度

编程入门 行业动态 更新时间:2024-10-11 11:23:22
本文介绍了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

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阵列的时间/空间复杂度

本文发布于:2023-11-29 13:47:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1646559.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:复杂度   阵列   时间   空间   PHP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!