Bucket Sort, Selection




CS146

Chris Pollett

Mar 12, 2014

Outline

Introduction

Bucket Sort

BUCKET-SORT Pseudo-code

BUCKET-SORT(A)
1 n = A.length
2 let B[0..n-1] be a new array
3 for i = 0 to n - 1
4    make B[i] an empty list
5 for i = 1 to n
6    insert A[i] into list B[floor(nA[i])]
7 for i = 0 to n - 1
8    sort list B[i] with insertion sort
9 concatenate the lists B[0], B[1], ... , B[n - 1] together in order

Example

Example of Bucket Sort on an input A

Remarks on Correctness

Expected Run-time

Towards showing `E[n_i^2] = 2 - 1/n`

`E[n_i^2] = 2 - 1/n`

Expected Run-time of BUCKET-SORT

Median and Order Statistics

Naive Selection Algorithm

Selection in Expected Linear Time