Algorithms and Data Structures · Middle · Question 73 of 75

What does it cost to insert a value into a sorted array and keep it sorted?

Explanation

Binary search finds the position quickly, but splice still moves every later element. For many inserts with lookups in between, a balanced tree or a heap (depending on the queries) is a better fit.

Further reading

Problem with a question

Algorithms and Data Structures · Middle · question 73

Test yourself

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

Take this quiz