1. Brief Introduction
This article mainly describes the classification, complexity, and stability of some common internal sorting algorithms. Based on the current understanding and learning, for detailed and accurate complexity, see Wikipedia and other authoritative websites. For different implementations of some algorithms, the complexity is also different, the complexity provided here is the complexity of a relatively good algorithm.
2. Category
3. complexity and Stability
Bubble Sorting: obtains the complexity of O (N) in an order.
Fast sorting: Each recursion is a matter of N complexity. The number of recursion times depends on the sequence. When the order is reached, the recursion times N. the time complexity is O (N * LogN)
Insert sorting: obtains the complexity of O (N) in an ordered condition.
Hill sorting: The worst time and average time are determined based on the step size array. The worst time complexity of the current best algorithm is O (N * LogN ). Space is mainly required for step size arrays. Generally, there is no common factor between step sizes.
Insert sorting: the number of swapping times is much less than that of Bubble sorting. Because the CPU time required for switching is much longer than the CPU time required, and the n value is smaller than the hour, the sort is faster than Bubble sorting.
Heap sorting: heap sorting is a selection of sorting, select the N-1 times, each time select one from the heap, so the worst is N * LogN. The best time cannot be accurately estimated, basically N * LogN.
Merge Sorting: the complexity of this sort algorithm is irrelevant to the array initialization sequence. The number of merge operations is LogN, and the complexity of each sort is O (N). Therefore, the complexity is O (N * LogN)
Base sorting: k is the maximum number of digits in the array. For int, k <= 10 in decimal format. In terms of stability, the base sorting requires that stable sorting be used each time; otherwise, the correct result will not be obtained. Therefore, the stability here is necessary, and there is no possibility of instability. Other sorting methods, such as Bubble sorting, can be rewritten to unstable.
Count sorting: k is the range of values in the array, that is, K = max-min + 1. For int, the worst case is k = 2 ^ 32, that is, the array contains the maximum positive number and the minimum negative number.
Bucket sorting: because some buckets do not have data, assuming n data records are only divided into M buckets, O (N) + O (M * (N/m) * log (N/m) = O (N + N * (logn-logm )) = O (N + N * logn-N * logm) = O (N + N * (logn-logm). The more buckets are allocated, the closer it is to n. Counting sorting can be seen as a special case of Bucket sorting. Opening a bucket is very large until different values can be grouped into a bucket.
4. Reference
Wikipedia
Three linear sorting algorithms: Count sorting, bucket sorting and base sorting http://www.byvoid.com/blog/sort-radix/
Http://anwj336.blog.163.com/blog/static/8941520920109535025216/ of Bucket sorting and base sorting