Data structure-sorting

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
  • 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
 
Internal sorting
  Sort name Sorting characteristics
Simple ranking Bubble Sort (Bubble Sort)
  • Stable sort space
  • The best complexity, only one extra space O (1) 
Selection Sort
  • Unstable sort
  • Space complexity is optimal, only one extra space O (1) 
Insert Sort (Insertion Sort)
  • Stable sorting
  • Space complexity is optimal, only one extra space O (1) 
Hill Sort
  • Stable sorting
  • Space complexity is optimal, only one extra space O (1) 
Advanced Sorting Quick Sort
  • Unstable sort
  • The worst space complexity is O (n), the best is O (log2n)
Heap Sort
  • Unstable sort
  • Space complexity is optimal, only one extra space O (1) 
Radix Sort
  • Stable sorting
  • The space complexity is O (np), n is the number of original data, and p is the base 

 

Guess you like

Origin www.cnblogs.com/qpliang/p/12674643.html