Case

Complexity


Best Case

O(n log n)

Each partition splits the array into two equal halves, requiring log n levels of recursion, and at each level, we process n elements for partitioning.

Average Case

O(n log n)

On average, partitions are reasonably balanced, so the height of recursion remains close to log n.

Worst Case

O(n²)

Happens if the pivot is always the smallest or largest element (e.g., already sorted array with poor pivot choice). The recursion tree becomes skewed, and each level processes almost all n elements.



Space Complexity