In PHP docs, users has written many times like this way:

the complexity of array_pop() is **O(1).**

the complexity of array_shift() is **O(n).**

What does this mean in bold?

In PHP docs, users has written many times like this way:

the complexity of array_pop() is **O(1).**

the complexity of array_shift() is **O(n).**

What does this mean in bold?

It refers to Big O notation

Scroll down you will find definitions of O(1) and O(n)

1 Like

http://php.net/manual/en/function.array-pop.php

array_shift() requires a re-index process on the array, so it has to run over all the elements and index them.

You must have had trouble recognizing that when it was expressed mathematically.

What he was saying is 1 vs. n (number of array members)

In other words, taking one off the end is less work then taking one off the beginning.

2 Likes

A collection can be O(1) for access but O(n) for insert. Got it.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.