Sorting Complexity
Announcements
Where we’re going
| Best case | Worst case | |
|---|---|---|
| Insertion | \(O(n)\) | \(O(n^2)\) |
| Selection | \(O(n^2)\) | \(O(n^2)\) |
| Merge | \(O(n\log n)\) | \(O(n\log n)\) |
The complexity of a problem is the runtime of the fastest algorithm that solves it.
Today: the complexity of comparison based sorting.
Insertion, Merge, Quick, Radix, Selection: which are comparison based sorts?
Suppose you have an unsorted array of length \(n\): \(p_1\,p_2 \ldots p_n\). We need to produce a result for every possible arrangement.
Fundamental operation: compare 2 elements using \(<\).
Consider a decision tree that arises from a comparison based sorting algorithm on \(n\) items:
We need the shortest tree whose number of leaves is \(\ge\) the number of permutations.
What is the minimum height of a comparison tree for sorting input of size \(n\)?
Find the smallest \(k\) so that \(2^k \ge n!\)
Lower bound on comparison based sorting (\(n\) items)…
Minimum height of a comparison tree for sorting input of size \(n\)…
How tall are the trees for selection and insertion sort?
CPSC 221