What is the time complexity of Quick Sort?

What is the time complexity of Quick Sort?

Approach: Analyze average and worst-case scenarios based on pivot choice.

Average case O(n log n). Worst case O(n^2), occurring when the pivot consistently splits the array into very unbalanced partitions (e.g., if the array is already sorted).

Follow-up: How can you avoid the worst case? (Randomized pivot)

Key concepts: O(n log n) average, O(n^2) worst, pivot.