Datastructures/Sorting Algorithms

From PBDN

Jump to: navigation, search

Contents

Sorting Algorithms

Main Algorithms Studied

Summary of Sorting Algorithms
Algorithm Worst CT Avg. CT Best CT StableIn-placeOnlineInventor
Insertion sort O(n2) 0.25 * WCT O(n) Y Y Y  ?
Merge sort O(n\,\lg n) O(n\,\lg n) ? Y N Maybe John Von Neumann
Heapsort O(n\,\lg n) O(n\,\lg n) O(n\,\lg n) N Y N  ?
Quicksort O(n2) 1.39 * BCT O(n\,\lg n) N Maybe  ? C.A.R. (Tony) Hoare


Insertion Sort

Advantages: stable, in-place, O(n) on sorted lists, very simple: fast for very small lists (n < 10). Good locality-of-reference.

Merge Sort

Advantages: stable, good locality-of-references, parallelizes well, can be modified for online sorting, good choice for sorting linked lists.

Disadvantages: not in-place, quite complex to implement

Heapsort

Advantages: in-place, parallelizes poorly, quite simple to implement.

Disadvantages: not stable, poor locality-of-reference, not online.

Quicksort

Advantages: Can be implemented as in-place, often fast in practice, parallelizes well.

Disadvantage: not stable, poor worst-case performance with common worst-case, performance dependent on pivot choice.

Linear Time Algorithms

Counting Sort

Radix Sort

Bucket Sort

Back to Datastructures main page.