Benefits of sorting:
- The data is easier to read
- Data is more conducive to statistics and collation
- Can greatly reduce data search time
Sort by runtime memory
- Internal sorting: the amount of sorted data is small and can be sorted in memory
- Bubble sorting method, selection sorting method, insertion sorting method, merge sorting method, quick sorting method, stacked sorting method, Hill sorting method, cardinal sorting method
- Bubble sorting method, selection sorting method, insertion sorting method, merge sorting method, quick sorting method, stacked sorting method, Hill sorting method, cardinal sorting method
- External sorting: the amount of sorted data cannot be sorted directly in memory, but auxiliary storage (hard disk) must be used
- Direct merge sorting method, K-way merge method, multi-phase merge method
Sorting algorithm analysis
-
Whether the algorithm is stable
- Stable sorting means that after the data is sorted, two records with the same key value still maintain the original order
- Raw data: 7 (left) , 2, 9, 7 (right) , 6
- Stable sorting: 2, 6 , 7 ( left) , 7 (right) , 9
- Unstable ordering: 2, 6 , 7 ( right) , 7 (left) , 9
- Time complexity (omit coefficient, low order, constant)
- Best Case: The data has been sorted
- Worst Case: Every key value needs to be rearranged
- Average Case (Average Case): all times / all times
- Space complexity
- The extra memory space that the algorithm needs to pay during the execution process only uses one extra space, and the space complexity is the best
Sort name | Sorting characteristics | |
Simple ranking | Bubble Sort (Bubble Sort) |
|
Selection Sort |
|
|
Insert Sort (Insertion Sort) |
|
|
Hill Sort |
|
|
Advanced Sorting | Quick Sort |
|
Heap Sort |
|
|
Radix Sort |
|