What is the worst-case time complexity of Quick Sort?
Practice Questions
Q1
What is the worst-case time complexity of Quick Sort?
O(n log n)
O(n^2)
O(n)
O(log n)
Questions & Step-by-Step Solutions
What is the worst-case time complexity of Quick Sort?
Step 1: Understand what Quick Sort is. It is a sorting algorithm that works by selecting a 'pivot' element and partitioning the array into two parts: elements less than the pivot and elements greater than the pivot.
Step 2: Know that the efficiency of Quick Sort depends on how well the pivot is chosen. A good pivot divides the array into two roughly equal parts.
Step 3: Recognize that in the worst-case scenario, the pivot is the smallest or largest element, which means one part will have almost all the elements and the other part will have very few or none.
Step 4: When this happens repeatedly, the algorithm will have to make many comparisons, leading to a time complexity of O(n^2), where n is the number of elements in the array.
Step 5: Conclude that the worst-case time complexity of Quick Sort is O(n^2) due to poor pivot selection.