1. Bubble Sorting
Algorithm: the core idea is to scan the data list to find two adjacent projects in disordered order. After the two items are found, switch the project location and continue scanning. Repeat the preceding operations until all projects are sorted in order.
2. Insert directly to sort
Algorithm: After I-1 processing, L [1 .. I-1] has been sorted. I-repeat only inserts L [I] into the proper position of L [1 .. I-1] so that l [1 .. I] is a sorted sequence. To achieve this goal, we can use the sequential comparison method. First compare L [I] and L [I-1], if l [I-1] ≤ L [I], then l [1 .. i] the order has been sorted, the I-th processing is over; otherwise, the position of switching L [I] and L [I-1] continues to compare L [I-1] and L [I-2], until a position J (1 ≤ j ≤ i-1) is found so that l [J] ≤ L [J + 1]
3. Simple selection and sorting
Algorithm: First, find the smallest data in the data list, and then change the data to the first data exchange location. Then, find the second small data, change it to the second data exchange location, and so on.
4. Fast sorting
Algorithm: First, check the number of data in the data list. If the number is smaller than two, exit the program directly. If there are more than two pieces of data, select a split point to divide the data into two parts. The data smaller than the split point is placed in one group, and the rest is placed in another group, sort the two groups of data respectively.
Generally, the split point data is randomly selected. In this way, no matter whether your data has been sorted or not, the size of the two word lists you split is similar. As long as the size of the two sublists is about the same
5. Heap sorting
(1) Basic Ideas:
Heap sorting is a tree-based sorting. During the sorting process .. n] As a Complete Binary Tree ordered storage structure, the use of the full binary tree between the parent node and the child node to select the smallest element.
(2). Heap definition: The sequence of n elements is K1, K2, K3,..., kN. It is called heap. if and only when the sequence satisfies the characteristics:
Ki ≤ k2i Ki ≤ k2i + 1 (1 ≤ I ≤ [n/2])
(1) If n is small (such as N ≤ 50), direct insertion or direct selection of sorting can be used.
When the record size is small, the direct insertion sorting is better; otherwise, the sorting should be selected because the number of records to be moved is less than the direct insertion.
(2) If the initial state of the file is basically ordered (positive), direct insertion, bubble or random quick sorting should be selected;
(3) If n is large, the time complexity is O (nlgn.
Quick sorting is the best method in comparison-based internal sorting. When the keyword to be sorted is a random distribution, the average time of quick sorting is the shortest;
The auxiliary space required for heap sorting is less than that for quick sorting, and the worst possible case for quick sorting is not displayed. The two sorting types are unstable.