Comparison Sorts Complexity
Comparison Sorts Complexity
depends on gap
Shell sort sequence. Best No Insertion
known: O(nlog2n)
Exchangi
Bubble sort Yes Tiny code size
ng
When using a self-
Binary tree sort Yes Insertion balancing binary search
tree
In-place with
Cycle sort — No Insertion theoretically optimal
number of writes
Library sort — Yes Insertion
Finds all the longest
Insertion
increasing
Patience sorting — — No &
subsequences within
Selection
O(n log n)
An adaptive sort -
comparisons when the
Smoothsort No Selection
data is already sorted,
and 0 swaps.
Strand sort Yes Selection
Tournament sort — Selection
Exchangi
Cocktail sort Yes
ng
Exchangi
Comb sort — — No Small code size
ng
Exchangi
Gnome sort Yes Tiny code size
ng
Example implementation
here: [4]; can be
In-place merge Depen
Merging implemented as a stable
sort ds
sort based on stable in-
place merging: [5]
Randomly permute the
Bogosort No Luck
array and check if sorted.