Long time not to learn the algorithm, a lot of things are forgotten, so come back to tidy up the original learned things, here sort all by default in ascending order for example
Say first 3 simple, time complexity O (n^2)
1. Bubble sort
Compare the two adjacent numbers, if the latter is smaller, then swap, so that after each end, you can put the number I in the correct position
2. Select sort
For the first time, look for the minimum value within the range of 0~n-1 and place it in position No. 0,
The second time in the range of 1~n-1 to find the minimum value, put it in position 1th,
Then and so on
3. Insert Sort
For the first time, the number at position 1th is compared to the number at position No. 0, and if the number in position 1th is smaller, the exchange
The second time the number in position 2nd is compared with the number at position 1th, if it is smaller than the number in position 1th, then the exchange, and then compared with the No. 0 position, if it is still relatively small, then the Exchange
Then and so on
4 algorithms that are relatively troublesome in the back
4. Merge sort
The algorithm is to think of the number in the array as a number of intervals of length 1, then the adjacent length of 2 of the interval is sorted, and then the length of 4 of the interval is sorted, and so on.
5. Quick Sort
The algorithm chooses a random number in the array, divides the entire array into two regions, and then carries out the above operation again on the left and right two regions, recursively, and finally gets the ordered array.
6. Heap Sequencing
The array elements are first formed into a large heap
The top of the heap is exchanged with the end of the heap, and the elements at the end of the heap are removed, and then the heap is adjusted to a large heap.
Repeat the process until there are no elements in the heap, you can get the sorted array
7. Hill sort
The hill sort is an optimized insert sort, the key is the choice of step size, with the array length of 8 as an example, the first time you can choose the step size of 3 to sort
Then select the step to sort by 2 and select Step 1 to sort
Summary of sorting algorithm ideas