Selection - Quick-Sort 4/1/2003 8:56 AM The Selection...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Selection 1 Selection Selection 2 The Selection Problem Given an integer k and n elements x 1 , x 2 , …, x n , taken from a total order, find the k-th smallest element in this set. Of course, we can sort the set in O(n log n) time and then index the k-th element. Can we solve the selection problem faster? 7 4 9 6 2 2 4 6 7 9 k=3 Selection 3 Quick-Select (§10.7) Quick-select is a randomized selection algorithm based on the prune-and-search paradigm: ± Prune : pick a random element x (called pivot ) and partition S into ² L elements less than x ² E elements equal x ² G elements greater than x ± Search : depending on k, either answer is in E , or we need to recur on either L or G x x L G E k < | L | |L| < k < | L |+| E| (done) k > | L |+| E| k’ = k - |L| - |E| Selection 4 Partition We partition an input sequence as in the quick-sort algorithm: ± We remove, in turn, each element y from S and ± We insert y into L , E or G , depending on the result of the comparison with the
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/02/2012 for the course CS 251 taught by Professor Staff during the Fall '08 term at Purdue University.

Page1 / 2

Selection - Quick-Sort 4/1/2003 8:56 AM The Selection...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online