Classic sorting algorithm-flash sort
Flashsort is still similar to bucket scheduling. It mainly improves the prediction of the bucket to be used, or reduces the number of useless buckets, thus saving space. For example
The number to be sorted [6 2 4 1 5 9 100] requires 100 buckets, while Flash sort requires only 7 buckets because the number can be predicted.
That is to say, the length of the bucket to be arranged in the array. How to predict the bucket to be used has such a formula?
This sorting hasYou need to know the range of the array to be sorted and the length of the array to be sorted,
For example, it is known that the length of the array to be arranged [6 2 4 1 5 9] is 6, the maximum value is 9, and the minimum value is 1. The three conditions are known, if you cannot know the three, you cannot apply the sorting.
Idea of Prediction
If there is such an array to be arranged, its maximum value is 100, its minimum value is 1, and its length is 100, then 50 is very likely to appear in the center after the sorting, flash sort is based on this idea
Prediction Bucket Number Details
Array to be sorted [6 2 4 1 5 9]
For details, see Bucket Number 6.
Ai-Amin is 6-1 = 5
Amax-Amin is 9-1 = 8
M-1 is the array length 6-1 = 5
Then (m-1) * (AI-AMIN)/(amax-AMIN) = 5*5/8 = 25/8 = 3.125
Add 1 to 4.125
6. The predicted bucket is 4.125.
2. The predicted bucket is 1.625.
4. The predicted bucket is 2.875.
1. The predicted Bucket number is 1.
5. The predicted bucket is 3.5.
9. The predicted Bucket number is 5.
After decimal places are removed, each number has its own predicted Bucket number, which corresponds to the following:
Array to be sorted [6 2 4 1 5 9]
Predicted Bucket number [4 1 2 1 3 5]
Bucket logging rules
Bucket 1
Bucket 2 4
Bucket 3 5
Bucket 4 6
Bucket 5 9
Two numbers in the bucket 1 are ordered by any sorting algorithm. If other buckets need to be sorted in the bucket in this case, it is not important to use any sorting algorithm. What is important is to arrange the numbers from small to large.
The final order is extracted from the bucket.
[1 2 4 5 6 9]
Reference http://en.wikipedia.org/wiki/Flashsort
Back to main directory [classic Sorting Algorithm] [Collection]