Temporal / spatial complexity of a PHP array

Is there a way or resource to find the temporal and spatial complexity of an Array implementation in PHP, other than manually calculating it?

An array in PHP is actually an ordered map. A map is a type that associates values ​​with keys. This type is optimized for several different applications; it can be considered as an array, list (vector), hash table (map implementation), dictionary, collection, stack, queue, and possibly more. Other arrays can be used as array values, trees and multidimensional arrays are also possible. - php.net

From what I can say, it would seem that it has a total card complexity

+7
arrays complexity-theory php
Apr 12 2018-11-21T00:
source share
3 answers

Since it acts as a hash table, you will have O(1) time when accessing the element using the key.

If you iterate over an array, naturally you will have O(n) time.

If you have time, you can check the PHP implementation of the array here

+5
Apr 12 '11 at 20:24
source share

Access to iteration is described by @ Mike-Lewis so far

  • Setting value: O (1)
  • Add: O (1) (This is the same as setting the value to "length")
  • Prepend: O (n) (its a guess, but must match because it must rewrite existing keys)
  • Unset: O (1)

Is everything missing?

+2
Apr 12 2018-11-11T00:
source share

In addition to what @Mike Lewis said, I would add that one array element in PHP takes at least 52 bytes ( proof )

0
Apr 12 2018-11-11T00:
source share



All Articles