Summary of sorting algorithms
- Preface
- [1] Basic sorting algorithm for small data
- [2] (Derived from basic sorting for) processing big data processing sorting
- [3] Big data speed sorting method
- [4] Sorting of integer data types with extreme speed
- [5] Other sorting
- 1. Analysis and comparison of various sorting algorithms
- 2. Merge sort: Detailed explanation of the idea of external sorting algorithm
- ☆3. Stability concept explanation
- 4. Sorting algorithm complexity and stability analysis
- Summarize
Preface
I have previously told you about the principles, ideas, implementation steps, and code sources of the major sorting algorithms. Now let us compare the algorithm complexity and stability analysis of the major sorting algorithms to deepen our understanding of each sorting algorithm. Understanding helps us to more quickly choose the most appropriate sorting algorithm in specific scenarios in the future.
[1] Basic sorting algorithm for small data
(1) Bubble sorting
[Data structure] Bubble sort (code source implementation)
(2) Direct insertion sort
[Data structure] Insertion sort
[2] (Derived from basic sorting for) processing big data processing sorting
(1) Heap sort
[Data structure] Heap sort (C code implementation code source)
(2) Hill sorting
[3] Big data speed sorting method
(1) Quick sort
(2) Merge sort
[Data Structure] Recursive and non-recursive implementation of merge sort
[4] Sorting of integer data types with extreme speed
(1) Counting sorting
[5] Other sorting
(1) Radix sort: compare one by one
(2) Bucket sorting
I won’t go into details about these two types here because they are not as good as the previous advanced sorting and are more applicable.
1. Analysis and comparison of various sorting algorithms
Inner sorting: sorting in memory
External sorting: Sorting on disk [Too much data cannot be stored in the memory, so it is transferred to the disk]
- A major feature of the disk:
- Sequential read Sequential write
- It does not support subscript access like memory, so external sorting will be very slow.
Merge sort can be sorted in memory (inner sort) or on disk (outer sort)
2. Merge sort: Detailed explanation of the idea of external sorting algorithm
☆3. Stability concept explanation
After the same data is sorted, does the relative position change?
The meaning and practical application of stability:
If in the exam, the top three are ranked first, the paper will be submitted firstThe paper that takes less time will be entered into the array first
In the ranking, the one with higher scores will have higher priority. If the scores are the same, the one with the shorter time will have higher priority
or if the total score is the same, the one with higher math score will have higher priority.
This is often used for structural sorting ( Use the structure pointer to sort by a certain One item to compare )
4. Sorting algorithm complexity and stability analysis
- Direct insertion sorting is stable and will not move forward when encountering equality.
-
- Merge sorting is unstable and becomes stable
Most of them are structure pointers. Talking about stability, counting sorting is worthless talking about stability.
- Merge sorting is unstable and becomes stable
Summarize