Algorithms and Data Structures · Junior · Question 7 of 75
Which array operation is usually O(n) in JavaScript?
- ✓Correct answer:
arr.shift() - 2
arr.push(x) - 3
arr.pop()
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).