I find this in a Java document.
The sorting algorithm is a double rotary quick sorting by Vladimir Yaroslavsky, John Bentley and Joshua Bloch. This algorithm provides O (n log (n)) performance for many datasets, which lead to a deterioration in the quadratic performance of other quick sorts, and, as a rule, faster than traditional implementations (with one turn) of quick sort.
Then I find it in Google search results. Here is a quick sort algorithm:
- Select an element called a summary from the array.
- Reorder the array so that all elements smaller than the summary appear before the summary, and all elements larger than the summary follow it (equal values ββcan occur anyway). After this splitting, the rotation element is in its final position.
- Recursively sort a nested array of smaller elements and a nested array of large elements.
For comparison: quick sort with two pivot points:
(
)
- For small arrays (length <17), use the insertion sorting algorithm.
- Select the two pivots P1 and P2. For example, we can get the first element a [left] as P1 and the last element a [right] as P2.
- P1 must be less than P2, otherwise they will change places. So, there are the following parts:
- part I with indices on the left + 1 to L - 1 with elements that are less than P1,
- Part II with indices from L to K - 1 with elements that are greater than or equal to P1 and less than or equal to P2,
- part III with indices from G + 1 to the right - 1 with elements greater than P2,
- Part IV contains the remaining elements that need to be investigated with indices from K to G.
- The next element a [K] from part IV is compared with the two axes P1 and P2 and placed in the corresponding part I, II or III.
- Pointers L, K and G change in the corresponding directions.
- Steps 4 - 5 are repeated until K β€ G.
- The rotary element P1 is replaced by the last element from part I, the rotary element P2 is replaced by the first element from part III.
- Steps 1 through 7 are repeated recursively for each part I, part II, and part III.
Brutal_JL Jan 04 '14 at 6:43 2014-01-04 06:43
source share