The quick sort algorithm is a divide-and-conquer algorithm that can be implemented using a recursive function. The following graphic explains the different steps of a quick sort algorithm.
Note, that the quick sort algorithm starts by identifying a pivot. Depending on the implementation, this pivot can be one of the following three values:
- The first value of the list of values to be sorted,
- The mid-value of the list,
- The last value of the list.
The example below uses the mid-value of the list (value in the middle position):
Here is our Python implementation of a quick sort algorithm using a recursive function. This implementation uses the mid-value as the pivot.