Some optimizations include improving the code so that work is done once before a loop rather than inside a loop or replacing a call to a simple selection sort with a call to the more complicated algorithm for a quicksort.
32.
In this algorithm, a variation of selection sort, we bring the largest pancake not yet sorted to the top with one flip, and then take it down to its final position with one more, then repeat this for the remaining pancakes.
33.
It produces at least twice as many writes as insertion sort, twice as many cache misses, and asymptotically more Java show bubble sort to be roughly one-fifth as fast as an insertion sort and 70 % as fast as a selection sort.
34.
Insertion sort's advantage is that it only scans as many elements as it needs in order to place the " k " + 1st element, while selection sort must scan all remaining elements to find the " k " + 1st element.
35.
As an example, consider the sorting algorithms selection sort and insertion sort : Selection sort repeatedly selects the minimum element from the unsorted remainder and places it at the front, which requires access to the entire input; it is thus an offline algorithm.
36.
---- Note the resemblance to quicksort : just as the minimum-based selection algorithm is a partial selection sort, this is a partial quicksort, generating and partitioning only O ( log " n " ) of its O ( " n " ) partitions.
37.
As an example, consider the sorting algorithms selection sort and insertion sort : Selection sort repeatedly selects the minimum element from the unsorted remainder and places it at the front, which requires access to the entire input; it is thus an offline algorithm.
38.
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.
39.
The obvious linear time algorithm to find the minimum ( resp . maximum ) iterating over the list and keeping track of the minimum ( resp . maximum ) element so far can be seen as a partial selection sort that selects the 1 smallest element.
40.
If the latter, it could easily be a self-selection sort of thing, a factor of who is driven into the profession more than what the profession does to one . ( And of course, in practice, these things are probably complementary . )-- talk ) 14 : 01, 29 June 2010 ( UTC)