What is the worst-case time complexity of Quick Sort?
a) O(n log n)
b) O(n)
c) O(n^2)
d) O(log n)
Answer:
c) O(n^2)
Explanation:
Quick Sort has a worst-case time complexity of O(n^2), which occurs when the pivot chosen is always the smallest or largest element in the array. This results in highly unbalanced partitions, causing the algorithm to degrade to quadratic time complexity.
However, with good pivot selection techniques, such as choosing a random pivot or the median, the average-case time complexity of Quick Sort is O(n log n), which makes it very efficient for large datasets.
In practice, Quick Sort is often faster than other O(n log n) algorithms like Merge Sort due to better cache performance and fewer data movements.
Reference:
DSA (Data Structures and Algorithms) MCQ Questions and Answers