Abstract
Best sort algorithm (merge sort) will take at worst.
Quick Sort
Idea:
- Choose pivot
- Everything left of pivot is smaller, everything right of it is bigger ()
- Call quicksort on the left side and right side
Choosing a good pivot
- Random
- With high probability pivot within
- Likely Complexity:
DSelect
i.e. Median of medians approach- Rank is guaranteed to be between of the array slice
- Complexity: ……first term:
DSelect
, second term quicksort- → for some (=)
Merge Sort
Idea:
- Split into two
- Call mergesort on each left, right side
- merge left, right side in time
alg. Parallel Merge Idea: For the 8 elements shown below, can we find out how to place the element in parallel (8 simultaneous processes)? → We can!
- Left half: binary search on right half for correct place
- Right half: binary search on left half for correct place
- Span
then we have… alg. Parallel Merge Sort
- Span
- Work
- Second term is work done by parallel merge procedure: correctly placing items, each takes .
alg. Inversion Counting. In an unsorted array count how many pairs are not in the correct order
- Idea: Mergesort, but during the merge step check how many times you need to reverse the pairs
Partially Sorted
Uses of partially sorted arrays:
- Top items: e.g. Google Search, College Admissions
- -th largest/smallest item
-th smallest item (=item of rank ) => use Tournament Tree