Complexity of Time
N^2 represents the square of N, and select sort is sometimes called direct select sort or simple select sort
| Sorting methods |
Average Time |
Best time |
Worst time |
| Bucket sequencing (unstable) |
O (N) |
O (N) |
O (N) |
| Cardinal Sort (Stable) |
O (N) |
O (N) |
O (N) |
| Merge sort (Stable) |
O (NLOGN) |
O (NLOGN) |
O (NLOGN) |
| Quick Sort (unstable) |
O (NLOGN) |
O (NLOGN) |
O (n^2) |
| Heap sort (unstable) |
O (NLOGN) |
O (NLOGN) |
O (NLOGN) |
| Hill Sort (unstable) |
O (n^1.25) |
|
|
| Bubble sort (Stable) |
O (n^2) |
O (N) |
O (n^2) |
| Select Sort (unstable) |
O (n^2) |
O (n^2) |
O (n^2) |
| Direct Insert sort (Stable) |
O (n^2) |
O (N) |
O (n^2) |
O (n) Such a sign is called asymptotic time complexity, which is an approximation. The order of the various asymptotic complexity from small to large is as follows
O (1) < O (Logn) < O (n) < O (Nlogn) < O (n^2) < O (n^3) < O (2^n) < O (n!) < O (n^n)
The general time complexity to 2^n (exponential order) and greater time complexity, such an algorithm we basically do not use, too impractical. For example, the recursive implementation of the Nottingham Tower problem algorithm is O (2^n).
The square order (n^2) algorithm is barely available, while the NLOGN and smaller time complexity algorithms are very efficient algorithms.
Complexity of Space
Bubble sort, simple selection sort, heap sort, direct insert sort, the spatial complexity of the hill sort is O (1), because a temporary variable is needed to swap the element position (and in addition, a variable is used to index the sequence)
The fast sort space complexity is logn (because recursive calls), the merge sort space is O (n), and a temporary array of size n is required.
The spatial complexity of the base sort is O (n), and the spatial complexity of bucket ordering is uncertain
The fastest sort algorithm is the bucket sort
The fastest of all sorting algorithms should be the bucket sort (many people mistakenly think that it is a quick sort, not actually.) But the bucket sort is generally not used much, because there are a few relatively large defects.
1. The element to be sorted cannot be a negative number, a decimal number.
2. Spatial complexity is uncertain, and the maximum value of the ordered element is to be seen.
The required auxiliary array size is the value of the largest element.