Algorithms and Data Structures · Junior · Question 75 of 75

How does arr.splice(i, 1) in the middle of an array affect performance?

Explanation

Removing from the middle keeps the array dense, so everything after the index moves. Deleting many elements one by one in a loop is O(n²); filter into a new array is O(n).

Further reading

Problem with a question

Algorithms and Data Structures · Junior · question 75

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