[Project Combat] Quick Sort of Sorting Algorithms

1. What is quick sort?

Quick sort (Quick Sort) is an efficient sorting algorithm
Quick sort (Quick Sort) uses a divide and conquer strategy to divide a sequence into two subsequences.
The average time complexity of quicksort is O(n log n), and the worst case time complexity is O(n^2).
In practical applications, quicksort is usually an efficient and widely used sorting algorithm.

Second, the core steps of quick sort

The core step of the algorithm is the partition (Partition) operation, which divides the data to be sorted into two independent parts through a sorting pass, and all the data in one part is smaller than all the data in the other part, and then follow this method. The two parts of data are quickly sorted separately, and the whole process can be performed recursively so that the entire data becomes an ordered sequence.

The steps of quick sort are as follows:

(1) Pick an element from the array, called "pivot",
(2) Reorder the array, all elements smaller than the pivot value are placed in front of the pivot, and all elements larger than the pivot value are placed in the pivot behind (the same number can go to either side). After this division is complete, the datum is in the middle of the sequence. This is called a partition operation.
(3) Recursively (recursively) quickly sort the sub-arrays of elements smaller than the reference value and the sub-arrays of elements greater than the reference value.

3. Quick Sort Algorithm Design Ideas

Through the idea of ​​​​divide and conquer, a large problem is decomposed into several small problems, and then these small problems are solved recursively, and finally the solutions of the small problems are combined to achieve the purpose of solving the original problem.

Quicksort uses recursive functions to implement sorting, so it is necessary to maintain a stack to save the context of each layer of recursive calls.

Guess you like

Origin blog.csdn.net/wstever/article/details/129927209