Section 415, Python commonly used sorting algorithm learning

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
Sort

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

 

Bubble Sort

Bubble Sort is a relatively simple sorting computer science .
It repeatedly walks through the sequence to be sorted, comparing two elements at a time, and swapping them if they are in the wrong order. The work of visiting the sequence is repeated until no more exchanges are needed, that is, the sequence has been sorted.
The name of this algorithm comes from the fact that larger elements will slowly "float" to the top of the sequence by swapping, hence the name.
 
 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324765004&siteId=291194637