Sorting Properties
- We have looked at two sorts, merge and quick.
- There are many sorts and they have been studied extensively.
- We can identify a number of properties
- In place vs requires extra memory.
- Merge sort requires two copies of the data at each level. It is not in place.
- Quicksort does not, it is in place.
- Stable
- If two elements have the same key, will their relative position be maintained.
- This is useful if you sort on multiple keys
- Sort by first name, then by last name.
- The list will be ordered by last names, but ordered within groups of last names by first name.
- Merge sort can be implemented as stable (normal implementation)
- Quick sort can not.
- We also consider performance
- Merge sort is $\Omega(n \log n)$
- Quicksort is $O(n \log n$ on average but $O(n^2)$ in the worst case.
- But we saw, quicksort outperforms merge sort in most cases.