Summarize:
Categories with large sorting can be divided into two types: inner and outer sort. In the sort process, all records are stored in memory, which is called an inner sort, and is called an out-of-order if you need to use external memory during sorting. The sort that follows is an inner sort.
Within a sort can be divided into the following categories:
(1), insert Sort: Direct insert sort, dichotomy insert sort, hill sort.
(2), select Sort: Simple select sort, heap sort.
(3), Exchange sort: bubble sort, quick sort.
(4), merge sort
(5), base sort
First, Stability:
Stabilize: Bubble sort, insert sort, merge sort, and Cardinal sort
Instability: Select sort, quick sort, hill sort, heap sort
Second, the average time complexity
O (n^2): Direct insert Sort, simple select sort, bubble sort.
In the case of small data size (9W), the direct insertion of the sort, simple selection of sort almost. The bubbling sorting algorithm has the highest time cost when the data is large. The Performance O (n^2) algorithm is basically a comparison of adjacent elements, which are basically stable.
O (NLOGN): Quick Sort, merge sort, hill sort, heap sort.
Among them, the fastest row is the best, followed by the merger and Hill, heap sorting in the data is very large when the effect is obvious.
Three, the choice of sorting algorithm
1. Small Data size
(1) In the case of the basic sequence of the sequence to be sorted, you can choose the direct insertion sort;
(2) The stability is not required to use simple selection of sorting, stability requirements should be inserted or bubbling
2. Data size is not very large
(1) Completely can use memory space, the sequence is disorderly, there is no requirement for stability, fast sorting, at this time to pay the log (N) extra space.
(2) The sequence itself may be orderly, to the stability of the requirements, space permitting, it is appropriate to use the merge sort
3. Data size is large
(1) For the stability of the request, you can consider the merger sort.
(2) Not required for stability, should be sorted by heap
4. Sequence initial basic order (positive order), preferably with direct insertion, bubbling
Sort--Summary