Datastructures/Sorting Algorithms
From PBDN
Contents |
Sorting Algorithms
Main Algorithms Studied
| Algorithm | Worst CT | Avg. CT | Best CT | Stable | In-place | Online | Inventor |
|---|---|---|---|---|---|---|---|
| Insertion sort | O(n2) | 0.25 * WCT | O(n) | Y | Y | Y | ? |
| Merge sort | | | ? | Y | N | Maybe | John Von Neumann |
| Heapsort | | | | N | Y | N | ? |
| Quicksort | O(n2) | 1.39 * BCT | | 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.