next up previous
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 $\leq$ i $\leq$ n.
Output:
x $\in$ 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 = \(\frac{n+1}{2}\): median (actually \(\lfloor\frac{n+1}{2}\rfloor\) and \(\lceil\frac{n+1}{2}\rceil\)).
Simple Solution:
Sort(A)
return(A[i]).
This is O(nlgn).


next up previous
Next: Up: Previous: