Linear-Time Median Selection
Given a “black box” O(n) median algorithm, what can we do?
- ith order statistic:
- Find median x
- Partition input around x
- if (i ? (n+1)/2) recursively find ith element of first half
- else find (i - (n+1)/2)th element in second half
- T(n) = T(n/2) + O(n) = O(n)
- Can you think of an application to sorting?