Reprint please indicate the source:
http://blog.csdn.net/gane_cheng/article/details/52652705
Http://www.ganecheng.tech/blog/52652705.html (better browsing effect)
The sorting algorithm has evolved over a long period of time, resulting in a number of different methods. For beginners, it is important to organize them to facilitate the understanding of memory. Each algorithm has its own specific use situation, it is difficult to general. Therefore, it is necessary for us to generalize all the common sorting algorithms.
Sorting large categories can be divided into two types: inner and outer sort. In the sort process, all records are stored in memory, which is called the inner sort, and if you need to use external storage in the sorting process, it is called the outer sort. The sort that follows is all about the inner sort.
The inner sort can be divided into the following categories:
(1), insert sort: direct insertion sort, binary insertion sort, hill sort.
(2), select Sort: Direct select sorting, heap sort.
(3), Exchange sort: bubble sort, quick sort.
(4), merge sort
(5), Cardinal Order
form Version
Sorting Method |
complexity of Time (average) |
complexity of Time (worst) |
Complexity of Time (best) |
Complexity of Space |
Stability |
Complexity |
Insert sort directly |
O (n2) O (n^2) |
o (n2) O (n^2) |
o (n) o (n) |
O (1) o (1) |
stable |
simple |
Hill sort |
o (nlog2n) O (nlog_{2}n) |
o (n2) o (n^2) |
o (n) o (n) |
o (1) O (1) |
unstable |
more complex |
Select sort directly |
O (n2) O (n^2) |
o (n2) O (n^2) |
o (n2) O (n^2) |
O (1) O (1) |
unstable |
simple |
heap sort |
o (nlog2n) O (nlog_{2}n) |
o (nlog2n) O (n log_{2}n) |
o (nlog2n) O (nlog_{2}n) |
O (1) O (1) |
unstable |
more complex |
Bubble Sort |
O (n2) O (n^2) |
O (n2) |