Algorithms and Data Structures · Junior · Question 40 of 75

When is insertion sort a good choice?

Explanation

Insertion sort is O(n²) in general but close to O(n) on nearly sorted data, and it has very low overhead. That's why Timsort uses it for short runs inside its O(n log n) algorithm.

Further reading

Problem with a question

Algorithms and Data Structures · Junior · question 40

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