Insertion Sort

Back to Comparison-Based

Builds the sorted array one element at a time by inserting each element into its correct position. O(n^2) worst case but O(n) on nearly sorted data. Stable and in-place. Used as a building block in hybrid sorts like Timsort.

algorithms sorting insertion-sort