next up previous
Next: Up: Previous:

Select2

O(n)
Divide n elements into \(\lfloor n/5 \rfloor\) groups of 5 elements and one group of (n mod 5) elements
O(n)
Find median of each group.
T($\lceil$(n/5)$\rceil$)
Use Select2 recursively to find median of \(\lceil \frac{n}{5} \rceil\) medians
O(n)
Partition n elements around median into k and n-k elements.
T(7n/10 + 6)
If i $\leq$ k
then use Select2 to find ith element in k lower elements
else use Select2 to find (i-k)th element in n-k higher elements

Example

Click mouse to advance to next frame.


next up previous
Next: Up: Previous: