← Back to Gallery

Insertion Sort

Comparisons:0
Swaps:0
Array Accesses:0
Shifts:0
Status:Ready

Insertion Sort

Builds the sorted array one element at a time. Takes the next unsorted element and inserts it into its correct position in the sorted portion by shifting elements right.

Worst:   O(n²) (reverse sorted)
Average: O(n²)
Best:    O(n) (already sorted)
Space:   O(1)

Good for: small arrays, nearly-sorted data, online sorting (streaming data). Try "Nearly Sorted" to see O(n) best case!