Next:
Up:
Previous:
Select2
O(n)
Divide n elements into
groups of 5 elements and one group of (n mod 5) elements
O(n)
Find median of each group.
T(
(n/5)
)
Use Select2 recursively to find median of
medians
O(n)
Partition n elements around median into k and n-k elements.
T(7n/10 + 6)
If i
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: