Oh My AlgorithmKO
←
Sorting

Algorithms · Sorting

Sort the same array in eight different ways

All methods start with [6, 2, 8, 4, 9, 1, 5]. Choose one and follow each step.

O(n²) · Simple, but slower

O(n log n) · Divide for speed

Without comparisons

Compare at a glance

MethodAverageWorstExtra spacePreserves equal-value order
Bubble SortO(n²)O(n²)O(1)Yes
Insertion SortO(n²)O(n²)O(1)Yes
Selection SortO(n²)O(n²)O(1)No
Shell SortO(n log² n)O(n²)O(1)No
Quick SortO(n log n)O(n²)O(log n)No
Merge SortO(n log n)O(n log n)O(n)Yes
Heap SortO(n log n)O(n log n)O(1)No
Counting SortO(n + k)O(n + k)O(k)Yes

Learning topics