Quick Sort works by partitioning the input around a randomly chosen element from the input, and recursively doing the same on the 2 partitions till we get sub-arrays of size '2', at which point, sorting them is as easy as swapping 2 elements that are relatively out of place (as per their expected sorted order).