Summary of Elementary Sorts
Comparison of sorting algorithms
(online)
|
#compares |
#swaps |
#moves |
|
min | avg | max |
min | avg | max |
min | avg | max |
Selection sort |
n2 |
n2 | n2 |
n |
n | n |
. | . | . |
Bubble sort |
n |
n2 | n2 |
0 |
n2 | n2 |
. | . | . |
Insertion sort |
n |
n2 | n2 |
. | . | . |
n |
n2 | n2 |
Shell sort |
n |
n4/3 | n4/3 |
. | . | . |
1 |
n4/3 | n4/3 |
Which is best?
- depends on cost of compare vs swap vs move for Items
- depends on likelihood of average vs worst case
|