Time/Space complexity of PHP Array

后端 未结 3 527
爱一瞬间的悲伤
爱一瞬间的悲伤 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:01

    Because it acts like a hash table, you will have O(1) time when accessing an element by a key.

    If you are looping through the array, naturally you will have O(n) time.

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

提交回复
热议问题