Content deleted Content added
promote Blum et al to references |
Promote Floyd & Rivest to references |
||
Line 31:
*If the pivot were exactly at the median of the input, then each recursive call would have at most half as many values as the previous call, and the total times would add in a [[geometric series]] to <math>O(n)</math>. However, finding the median is itself a selection problem, on the entire original input. Trying to find it by a recursive call to a selection algorithm would lead to an infinite recursion, because the problem size would not decrease in each call.
*[[Quickselect]] chooses the pivot uniformly at random from the input values. It can be described as a variant of [[quicksort]], with the same pivoting strategy, but where quicksort makes two recursive calls to sort the two subcollections <math>L</math> and <math>R</math>, quickselect only makes one of these two calls. Its [[expected time]] is <math>O(n)</math>.{{r|clrs}}
*The [[median of medians]] method partitions the input into sets of five elements, and then uses some other method (rather than a recursive call) to find the median of each of these sets in constant time per set. It then recursively calls the same selection algorithm to find the median of these <math>n/5</math> medians, using the result as its pivot. It can be shown that, for this choice of pivot, <math>\max(|L|,|R|)\le 7n/10</math>. Thus, a problem on <math>n</math> elements is reduced to two recursive problems on <math>n/5</math> and at most <math>7n/10</math> elements. The total size of these two recursive subproblems is at most <math>9n/10</math>, allowing the total time to be analyzed as a geometric series adding to <math>O(n)</math>. Unlike quickselect, this algorithm is deterministic, not randomized.{{r|clrs|bfprt}} It was the first linear-time deterministic selection algorithm known,{{r|bfprt}} and is commonly taught in undergraduate algorithms classes as an example of a [[divide and conquer]] algorithm that does not divide into two equal subproblems. However, the high constant factors in its <math>O(n)</math> time bound make it unsuitable for practical use.
*Hybrid algorithms such as [[introselect]] can be used to achieve the practical performance of quickselect with a fallback to medians of medians guaranteeing worst-case <math>O(n)</math> time.
Line 61:
== History==
[[Quickselect]] was presented without analysis by [[Tony Hoare]] in 1965,{{r|hoare}} and first analyzed in a 1971 technical report by [[Donald Knuth]].{{r|floriv}} The first known linear time deterministic selection algorithm is the [[median
== See also ==
Line 86:
<ref name=clrs>{{Introduction to Algorithms|edition=3|chapter=Chapter 9: Medians and order statistics|pages=213–227}}; "Section 14.1: Dynamic order statistics", pp. 339–345</ref>
<ref name=floriv>{{citation
| last1 = Floyd | first1 = Robert W. | author1-link = Robert W. Floyd
| last2 = Rivest | first2 = Ronald L. | author2-link = Ron Rivest
| date = March 1975
| doi = 10.1145/360680.360691
| issue = 3
| journal = [[Communications of the ACM]]
| pages = 165–172
| title = Expected time bounds for selection
| volume = 18}}</ref>
<ref name=frederickson>{{cite journal
Line 97 ⟶ 108:
| volume = 104
| year = 1993}}</ref>
<ref name=hoare>{{citation
| last = Hoare | first = C. A. R. | author-link = Tony Hoare
| date = July 1961
| doi = 10.1145/366622.366647
| issue = 7
| journal = [[Communications of the ACM]]
| pages = 321–322
| title = Algorithm 65: Find
| volume = 4}}</ref>
<ref name=kpaths>{{cite journal
|