Data Structures and Algorithms abbreviated - Sorting Algorithm

Sorting Algorithm


  • How to analyze a "sorting algorithm"? Three aspects:

  • effectiveness
  1. The best case, worst case, where the average time complexity
  2. Time complexity of the coefficient, a constant, low-level
  3. And comparing the number of exchange (or mobile) number
  • Memory consumption
  1. Sorting place, the space complexity of O (1)
  • stability
  1. Concerned about the value of the item is the same, whether the sort order before and after the change, it means the same algorithm is stable
  • Sort compare

Bubble Sort efficient than insertion - Bubble Sort data exchange operation has three, only one insertion sort data movement operations, namely low complexity coefficient

Sorting Algorithm Is stable Whether in situ sequencing Best case Worst case Average case
Bubble Sort Yes Yes O (n) O (N 2 ) O (N 2 )
Insertion Sort Yes Yes O (n) O (N 2 ) O (N 2 )
Selection Sort no Yes O (N 2 ) O (N 2 ) O (N 2 )
  • Bubble sort - Operation adjacent interchange data comparison

  • Insertion sort - sorted and unsorted partial section, each sort never get a sorted into the appropriate positions interval (determined by comparison, the comparison done during data movement)

  • Selection Sort - sorted and unsorted partial section, each taking the smallest unsorted sorted items into the end of the interval, comparing the minimum value of the data movement is completed during the

 

 

O (n)

Guess you like

Origin www.cnblogs.com/wod-Y/p/11959650.html