Sorting Algorithm
-
How to analyze a "sorting algorithm"? Three aspects:
- effectiveness
- The best case, worst case, where the average time complexity
- Time complexity of the coefficient, a constant, low-level
- And comparing the number of exchange (or mobile) number
- Memory consumption
- Sorting place, the space complexity of O (1)
- stability
- 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)