Search code examples
algorithmcomplexity-theoryquicksort

Intuitive explanation for why QuickSort is n log n?


Is anybody able to give a 'plain english' intuitive, yet formal, explanation of what makes QuickSort n log n? From my understanding it has to make a pass over n items, and it does this log n times...Im not sure how to put it into words why it does this log n times.


Solution

  • Each partitioning operation takes O(n) operations (one pass on the array). In average, each partitioning divides the array to two parts (which sums up to log n operations). In total we have O(n * log n) operations.

    I.e. in average log n partitioning operations and each partitioning takes O(n) operations.