order statistics
play

Order Statistics Algorithm Quicksort(A, first, last) if first < - PowerPoint PPT Presentation

Order Statistics Algorithm Quicksort(A, first, last) if first < last then // // Partition reorders A[first . . . last] so // All elements of A[first . . . mid - 1] are A[mid] // All elements of A[mid + 1 . . . last] are > A[mid] //


  1. Order Statistics Algorithm Quicksort(A, first, last) if first < last then // // Partition reorders A[first . . . last] so // All elements of A[first . . . mid - 1] are ≤ A[mid] // All elements of A[mid + 1 . . . last] are > A[mid] // The original value of A[last] ends up as A[mid] mid ← Partition(A, first, last) Quicksort(A, first, mid − 1) Quicksort(A, mid + 1, last)

  2. Order Statistics Algorithm Select1(A, first, last, i) if first = last then return A[first] mid ← Partition(A, first, last) leftsize ← mid − first if i = leftsize + 1 then return A[mid] if i ≤ leftsize then return Select1(A, first, mid − 1, i) return Select1(A, mid + 1, last, i − (leftsize + 1))

  3. Order Statistics Algorithm RandomizedQuickSelect(A, first, last, i) if first = last then return A[first] mid ← RandomizedPartition(A, first, last) leftsize ← mid − first if i = leftsize + 1 then return A[mid] if i ≤ leftsize then return RandomizedQuickSelect(A, first, mid − 1, i) return RandomizedQuickSelect(A, mid + 1, last, i − (leftsize + 1))

Recommend


More recommend