Insertion Sort
SortingavgO(n²)worstO(n²)spaceO(1)
73
8
48
12
77
50
51
20
30
57
23
12
72
50
80
88
35
70
32
68
A single element is already a sorted prefix
1 / 210
Size20
Distribution
Custom values2 to 150 whole numbers, each 1 to 999
seed 3
How it works
Grows a sorted prefix one element at a time: each new key is shifted left past every larger element until it reaches its place. It is very fast on nearly sorted input, which is why hybrid sorts use it for small runs.
Complexity
- Best
- O(n)
- Average
- O(n²)
- Worst
- O(n²)
- Space
- O(1)
- Stable
- Yes
- In place
- Yes