Quick Sort is a highly efficient sorting algorithm and is based on partitioning an array into smaller sub-arrays. It is also known as partition-exchange sort. Here is how it works:
- Pick an element, called a pivot, from the array.
- Reorder the array so that all elements with values less than the pivot come before it, while all elements with values greater than the pivot come after it. After this partitioning, the pivot is in its final position. This is called the partition operation.
- Recursively apply the above steps to the sub-array of elements with smaller values and separately to the sub-array of elements with greater values.
Did you know? Quick Sort is often faster in practice than other algorithms, like merge sort! 😊
For further reading, check these pages: