Time/Space complexity of PHP Array

后端 未结 3 521
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-16 00:38

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?

An array

3条回答
  •  借酒劲吻你
    2020-12-16 01:11

    Accessing and iterating is describe by @Mike-Lewis so far

    • Setting a value: O(1)
    • Append: O(1) (Its the same as setting a value to the key "length")
    • Prepend: O(n) (Its a guess, but should fit, because it should rewrite the existing keys)
    • Unset: O(1)

    Anything missed?

提交回复
热议问题