Content deleted Content added
revert last 4; links have little content |
|||
Line 3:
The simplest case of a selection algorithm is finding the minimum (or maximum) element by iterating through the list, keeping track of the running minimum – the minimum so far – (or maximum) and can be seen as related to the [[selection sort]]. Conversely, the hardest case of a selection algorithm is finding the median, and this necessarily takes ''n''/2 storage. In fact, a specialized median-selection algorithm can be used to build a general selection algorithm, as in [[median of medians]]. The best-known selection algorithm is [[quickselect]], which is related to [[quicksort]]; like quicksort, it has (asymptotically) optimal average performance, but poor worst-case performance, though it can be modified to give optimal worst-case performance as well.
== Selection by sorting ==
Line 35 ⟶ 33:
swap list[i] and list[minIndex]
'''return''' list[k]
== Partition-based selection ==
|