stability
If a sorting algorithm can be retained in the array relative position of the duplicate elements it may be called stable in
- Stable sorting algorithms: insertion sort, merge sort
- Unstable sorting algorithm: select sort, shell sort, quick sort and heap sort
Generally only in stability it is necessary, have the advantage of a stable sorting algorithm.
It features a variety of sorting algorithms
algorithm | Is stable | Whether in situ sequencing | time complexity | Space complexity | Remark |
---|---|---|---|---|---|
Selection Sort | no | Yes | N^2 | 1 | |
Insertion Sort | Yes | Yes | Interposed between the N and N ^ 2 | 1 | Depending on the arrangement of the input elements |
Shell sort | no | Yes | Nlogn? | 1 | |
Quick Sort | no | Yes | nlogn | LGN | Operating efficiency guaranteed by the probability |
Three-Quick Sort | no | Yes | Between N and NlogN | LGN | Operating efficiency guaranteed by probability, but also on the distribution of the input element |
Merge sort | Yes | no | nlogn | N | |
Heapsort | no | Yes | nlogn | 1 |
- Quick sort is the fastest general sorting algorithms.
If the stability is very important and the heavy air and see not a problem, merge sort is probably the best choice
Sorting algorithm Java library system
Java system programmer selection of the raw data (three-sliced) using Quicksort type of reference type and merge sort. It implies a velocity and space (for the type of raw data) exchange stability (for reference types).