An overview of the

Quicksort algorithm is an efficient sorting algorithm based on exchange and adopts the idea of divide-and-conquer.

The basic idea is as follows:

  1. To take a number from a sequence as a reference number
  2. Divide the array so that elements larger than the base number are moved to the right and elements smaller than the base number are moved to the left
  3. The left and right subintervals are repeatedly sorted until each subinterval has only one element

 

Its temporal and spatial complexity is as follows:

 

Quicksort is putting the small ones on the left, the big ones on the right, and doing it left to right.

Its code implementation is as follows:

 

At the same time, quicksort can also be divided into three groups, divided into greater than, equal to, less than three groups, for more repeated elements, such segmentation is better, can effectively avoid the comparison of equal elements, equal elements together, you do not have to cut these elements.