Quick sort is the fastest known comparision sort for arrays. To top it, it could be done in-place for arrays. For Linked Lists, Merge Sort might be a better option. Also since Quicksort improves its performance by using random numbers, it also becomes an example of a breed of algorithms named “Randomized Algorithms”.

Interestingly, Quicksort has a worst case running time of 0(n2). However, with careful implementations, n2 never happens and it almost always runs in 0(n log n). As compared to Heapsort, whose best and worst case is guaranteed to be n log n, Quicksort beats Heapsort in clock time for two reasons :

1) The constant factor surrounding the 0(nlogn) is lesser than Heapsort due to the very thin core logic. Heap sort’s detailed comparison and exchange mechanism inside loops increases the constant factor.

2) Quicksort could leverage on the locality of reference (and therefore, memory access) advantages provided by the hardware and the operating system

How n log n?

If you choose the pivot right, then, on an average, you get a 1/4, 3/4 split which gives an average running time of 0(n log n)

Choosing a random key as the pivot is the preferred method because of the guaranteed worst case possibility with the other selection methods with following kinds of sequences :

1) Presorted list
when chosing first item as your pivot in case of natural order
last item as your pivot in case of reverse order
2) Repeated elements
3) Unimodal sequences* (when median is chosen as pivot)

Bottom line : When you choose a pivot in such a way that one portion of your split (either I1 or I2) becomes empty AND if you are doing it all through the list, then you are essentially doing the split N times.