Sorting algorithm (unfinished)

The gods are silent-personal CSDN blog directory

I plan to make videos introducing detailed ideas, algorithm flow (PPT), and code implementation for each algorithm. Be prepared to do it slowly.

0. Stability analysis of sorting algorithm

1. Insertion sort/direct insertion sort

Similar to manually sorting playing cards, each element is placed in order into the front-ordered sub-array (at the beginning, this sub-array only has the first element). In implementation, the
target element is usually compared step by step while moving forward. Move left until you reach the order.
The time complexity is O(N^2) and the space complexity is O(1).
It is stable.

1.1 Hill sorting

Grouping is performed by insertion sort, and the number of groups gradually decreases to 1,
which is unstable.

2. Simple selection sorting

Find the smallest element in each iteration and put it at the front

3. Heap sort

First create an unordered heap, and then iterate over all non-leaf nodes (starting from the last one) to heap each one (roughly speaking, it is to study whether this node should sink to the child node, and sink all the way to the appropriate position) superior)

Each time the root node is taken out, heaped from top to bottom, and the new root node is placed at the location of the original last node.

4. Bubble sort

When a pointer slides, compare the size difference between the last digit and the pointer digit. If the former is larger and the latter is smaller, swap them. In short, the largest one is sent to the last digit every time. (You can add the flag mark. If it is already in order and there is no need to move, the next iteration will be stopped)

5. Quick sort

Divide the numbers into one large group and one small group at a time

6. Merge sort

  1. Split the entire array into many sequential small arrays (starting from 1 number), and merge the small arrays sequentially
  2. Merge two sequential sequences into one sequential sequence. Put a pointer in each of the two sequences, compare the size of the elements, then put the small element into the new space, and then move the pointer backward until one sequence is traversed.

7. Bucket sorting/box sorting

Divide into buckets and sort each bucket separately

8. Radix sort/distributive sort/bucket method

stable

O ( n log ⁡ ( r ) m ) O (n\log(r)m) O ( nlog(r)m)

1. Least Significant Digit first LSD method

(This abbreviation seems too misleading)

Allocate starting from the lowest number, and after each allocation, merge according to the group, and then redistribute until all the digits are allocated.

Suitable for small number sequences

2. Most Significant Digit first MSD method

Contrary to the LSD method, allocation starts from the highest bit as the base, and after each allocation, sub-buckets are established in the group for allocation until the last bit is allocated.

9. Counting sort

Just put it very roughly directly into the index of the new array by element.

References

  1. Radix sort_Baidu Encyclopedia
  2. JAVA's radix sorting LSD sequence_lsd algorithm java_two two two two's blog-CSDN blog

Guess you like

Origin blog.csdn.net/PolarisRisingWar/article/details/132915194