Section 415, Python commonly used sorting algorithm learning
Common sorting
name |
the complexity |
illustrate |
Remark |
Bubble Sort |
O(N*N) |
Think of the elements to be sorted as "bubbles" arranged vertically, and the smaller elements are lighter and therefore have to float upward |
|
Insertion sort Insertion sort |
O(N*N) |
Remove elements one by one, scan from back to front in the sorted element sequence, and place them in the appropriate position |
At first, the sorted element sequence is empty |
selection sort |
O(N*N) |
First find the smallest element in the unsorted sequence, store it at the beginning of the sorted sequence, then continue to find the smallest element from the remaining unsorted elements, and put it at the end of the sorted sequence. Recursively this way. |
|
quicksort Quick Sort |
O(n *log2(n)) |
First select the middle value, then put the smaller value on the left, and the larger value on the right (the specific implementation is to search from both sides, find a pair and then exchange). Then use this process (recursively) for both sides separately. |
|
HeapSort |
O(n *log2(n)) |
A sorting algorithm constructed using the data structure of heaps. A heap is an approximate complete binary tree structure and also satisfies the heap property: that is, the key value or index of a child node is always less than (or greater than) its parent node. |
Approximate Complete Binary Tree |
Hill sort SHELL |
O ( n 1+ ) 0<£<1 |
Choose a step size (Step), and then sort the cells with the interval as the step size. Recursively, the step size gradually becomes smaller until it is 1. |
|
Bin |
O(n) |
Set up several boxes, put all the records whose key is equal to k into the k-th box (allocate), and then connect the non-empty boxes end to end according to the sequence number (collect). |
A type of allocation sorting: sorting is achieved through the "distribution" and "collection" processes. |
http://www.jxiou.com/
http://www.jxiou.com/lu_yin_wang_zhan.html