You are on page 1of 1

Powered by AI

Bing

The time complexity of Quick Sort depends on the case:

1. Best Case Time Complexity: Ω(n log n)

The best case occurs when the partition process always picks the middle element as the pivot. As a
result, the array is divided into two halves which reduces the time complexity to Ω(n log n).

2. Average Case Time Complexity: Θ(n log n)

On average, the partition process divides the array into two nearly equal pieces. This results in a
time complexity of Θ(n log n).

3. Worst Case Time Complexity: O(n²)

The worst case occurs when the partition process always picks the greatest or smallest element as
the pivot. If the array is already sorted in increasing or decreasing order, the worst case occurs.
There is no partitioning, we get one subarray with n-1 elements and one with 0 elements. Hence,
the time complexity is O(n²).

The space complexity of Quick Sort is O(log n). This space is required for storing the recursive function stack.
The worst case space complexity of Quick Sort is O(n), this happens in the case of a skewed tree.

You might also like