Algorithms and Data Structures · Senior · Question 63 of 75

What is the complexity of Array.prototype.sort in V8 on an array that's already sorted?

Explanation

Timsort detects that the whole array is one ascending run and only does a linear check. This is one reason to prefer the built-in sort over a handwritten quicksort.

Further reading

Problem with a question

Algorithms and Data Structures · Senior · question 63

Test yourself

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

Take this quiz