Next:
Up:
Previous:
Medians and Order Statistics
The selection problem (assume distinct elements)
Input:
Set A of n numbers and integer i such that 1
i
n.
Output:
x
A such that x is larger than i-1 elements of A (x is the ith smallest element).
i=1:
minimum
i=n:
maximum
i =
:
median (actually
and
).
Simple Solution:
Sort(A)
return(A[i]).
This is O(nlgn).
Next:
Up:
Previous: