Algorithms and Data Structures · Junior · Question 40 of 75
When is insertion sort a good choice?
- ✓Correct answer: For small or almost sorted arrays
- 2For huge arrays of random numbers
- 3When the data doesn't fit in memory
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.