The quick sort is probably the most used sorting algorithm. It has a complexity of O(n log n), and it usually performs better than other O(n log n) sorting algorithms. Similarly to the merge sort, it also uses the divide-and-conquer approach, dividing the original array into smaller ones (but without splitting them as the merge sort does) to do the sorting.
The quick sort algorithm is a little bit more complex than the other ones you have learned so far. Let's learn it step by step, as follows:
- First, we need to select a value from the array called pivot, which will be the value at the middle of the array.
- We will create two pointers (references)—the left-hand side one will point to the first value of the array, and the ...