Algorithms and Data Structures · Junior · Question 7 of 75

Which array operation is usually O(n) in JavaScript?

Explanation

shift removes the first element, so every remaining element has to move one position to the left. push and pop work at the end of the array and are O(1) (amortized for push).

Further reading

Problem with a question

Algorithms and Data Structures · Junior · question 7

Test yourself

Take the Algorithms and Data Structures · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz