next up previous
Next: Analysis Up: l4 Previous: Random-Partition

Select2

  1. O(n): Divide n elements into \(\lfloor n/5 \rfloor\) groups of 5 elements and one group of (n mod 5) elements
  2. O(n): Find median of each group.
  3. T($\lceil$(n/5)$\rceil$): Use Select2 recursively to find median of \(\lceil \frac{n}{5} \rceil\) medians
  4. O(n): Partition n elements around median into k and n-k elements.
  5. 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: Analysis Up: l4 Previous: Random-Partition