Sequencing is a skill that every software development engineer needs to master , contain Python It's the same with engineers , that Python What are the sorting algorithms ? Common sorting algorithms are divided into insertion sorting 、 Shell Sort 、 Selection sort 、 Bubble sort 、 Quick sorting, etc , Next, follow Xiaobian to have a deep understanding .

Bubble sort

It is a simple and intuitive sorting algorithm , Repeated visits to the sequence to be sorted , Compare two elements at a time , If they're in the wrong order, exchange them . The job of the interview sequence is to repeat until there is no need to exchange , That is to say, the sequence has been sorted , The name of this algorithm comes from the fact that smaller elements will float to the top of the sequence through exchange .

Insertion sort

Its principle should be the easiest to understand , Because anyone who has played poker should be able to understand in seconds . Insert sort is the simplest and most intuitive sort algorithm , It works by building an ordered sort , For unsorted data , Scan backward and forward in sorted series , Locate and insert .

Shell Sort

Also known as the descending incremental sort algorithm , Is a more efficient version of insert sorting , But Hill sort is an unstable sort algorithm . Hill sort is based on the following two properties of insertion sort ： Insert sort is used to manipulate almost ordered data , Efficient , That is, the efficiency of linear sorting can be achieved ; But insertion sorting is generally inefficient , Because insertion sorting can only move data one bit at a time .

Merge sort

It is an effective sorting algorithm based on merge operation , This algorithm is a very typical application of divide and conquer method , Algorithm application as a typical idea of divide and rule .

Quick sort

The quick sort is by Tony · A sort algorithm developed by Hall . On average , Sort n Item to be Ο(nlogn) Compare it to . In the worst case Ο(n2) Compare it to , But it's not common . In fact, quicksort is usually significantly better than the others Ο(nlogn) Algorithm faster , Because its internal loop can be implemented efficiently on most architectures .

Count sorting

The core of counting and sorting is to convert the input data values into keys and store them in the extra array space . Sort as a linear time complexity , Counting sort requires that the data entered must be an integer with a defined range .

Radix sorting

Cardinality sorting is a non comparative integer sorting algorithm , The principle is to cut integers into different numbers according to the number of digits , Then compare each digit separately . Because integers can also express strings and floating-point numbers in specific formats , So Radix sorting is not only used for integers .