Comprehensive Comparison of Various Sorting Methods in Data Slave Structure

Hint: Sorting is a very important operation in computer programming. It rearranges an arbitrary sequence of data elements (or records) into a sequence ordered by keywords. It is very efficient to find elements in an ordered sequence. , but unordered sequences can only be searched one by one, so how to sort, especially efficient sorting, is an important topic.


foreword

Sorting: The so-called sorting is the operation of arranging a series of records in ascending or descending order according to the size of one or some keywords.
Stability: Assuming that there are multiple records with the same keyword in the sequence of records to be sorted, if sorted, the relative order of these records remains unchanged, that is, in the original sequence, r[i]=r[j] , and r[i] is before r[j], and in the sorted sequence, r[i] is still before r[j], then the sorting algorithm is said to be stable; otherwise, it is said to be unstable.
Internal sorting: Sorting in which data elements are all placed in memory.
External sorting: There are too many data elements to be placed in memory at the same time, and the sorting of data cannot be moved between internal and external memory according to the requirements of the sorting process.


提示:以下是本篇文章正文内容,下面案例可供参考

1. Time performance

1. Average time performance
Time complexity is O(nlog 2 n): Quick sort, heap sort and merge sort
time complexity is O(n 2 ): direct insertion sort, bubble sort and simple selection sort

2. When the sequence of records to be sorted is ordered in the order of keywords,
direct insertion sorting and bubble sorting can achieve the time complexity of O(n), and
the time performance of quick sorting is reduced to O(n 2 )

3. The time performance of simple selection sort, heap sort and merge sort does not change with the distribution of keys in the record sequence.

2. Space performance

Refers to the amount of auxiliary space required during the sorting process

1. The space complexity of all simple sorting methods (including: direct insertion, bubble and simple selection) and heap sorting is O(1)

2. The quick sort is O(log 2 n), which is the auxiliary space required by the stack during the execution of the recursive program

3. Merge sort requires the most auxiliary space, and its space complexity is O(n);

Third, the stability of the sorting method

1. Quick Sort, Simple Selection Sort, Heap Sort and Hill Sort are unstable sorting methods

2. For unstable sorting methods, as long as an example can be given to illustrate

Fourth, the lower bound of the time complexity of the sorting method

The various sorting methods discussed in the above link are all sorting methods based on the "comparison key".

It can be shown that the fastest possible time complexity of this sorting method is O(nlogn)

Summarize

Here are two pictures instead of the summary
insert image description here
Please add image description

Guess you like

Origin blog.csdn.net/rej177/article/details/124446028