next up previous
Next: Select2 Up: l4 Previous: Analysis

Random-Partition

   Random-Partition(A, p, r)
      i = Random(p, r)
      swap(A[p], A[i])
      return(Partition(A, p, r))



   Random-Select(A, p, r, i)
      replace Partition with Random-Partition
      replace Select with Random-Select



These are still \(\Theta(n^2)\) in the worst case
and O(n) in the average case.



However, we can get O(n) worst case performance with Select2.


next up previous
Next: Select2 Up: l4 Previous: Analysis