0% found this document useful (0 votes)
41 views2 pages

Comparison Sorts Complexity

Quicksort has the best average case performance but worst case performance depends on partitioning. Merge sort is stable, depends on merging, and was used to sort the table in Firefox. Heapsort has the best worst case performance and uses selection to sort.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views2 pages

Comparison Sorts Complexity

Quicksort has the best average case performance but worst case performance depends on partitioning. Merge sort is stable, depends on merging, and was used to sort the table in Firefox. Heapsort has the best worst case performance and uses selection to sort.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Comparison sorts

Average Worst Memor Stable Method


Name Best Other notes
y
Can be implemented as a
stable sort depending on
Depen Partitioni how the pivot is handled.
Quicksort
ds ng [citation needed]
 Naïve variants
use   space
Depend Used to sort this table in
Merge sort Yes Merging
s Firefox [2].
Heapsort No Selection
Average case is

Insertion sort Yes Insertion also  ,


where d is the number
of inversions
Partitioni Used
Introsort — No ng & in SGI STL implementat
Selection ions
Its stability depends on
the implementation.
Selection sort No Selection Used to sort this table in
Safari or other Webkit
web browser [3].
Insertion  comparisons when the
Timsort Yes & data is already sorted or
Merging reverse sorted.

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.

You might also like