Bucket sort is the simplest sort algorithm.

For example!

Now we have the following set of numbers

,3,6,3,2,9,0 [1]

Please sort the above numbers from smallest to largest.

If bucket sort is used, the steps are as follows.

1: takes the maximum value in the array. Here is the nine

2: Create an array of length 9+1. Store zeros in each element.

[0,0,0,0,0,0,0,0,0,0] the maximum index of the array is exactly the same as the maximum of the given array.

3: Iterates over the given array, giving the position of index 1 in the resulting array +1 when 1 occurs, and 3 when 3 occurs. Add 1 to index 3 in the array, and everything else is the same.

The resulting array is 0,1,1,1, 1,0,0,1,0,0,1,0,1.

4. In this way, the data will be in order and highly efficient. But it’s also a waste of space, because the length of the array depends on the maximum value in the original data +1!