The answer depends on strategy for choosing pivot. In early versions of Quick Sort where leftmost (or rightmost) element is chosen as pivot, the worst occurs in following cases.
1) Array is already sorted in same order.
2) Array is already sorted in reverse order.
3) All elements are same (special case of case 1 and 2)
Since these cases are very common use cases, the problem was easily solved by choosing either a random index for the pivot, choosing the middle index of the partition or (especially for longer partitions) choosing the median of the first, middle and last element of the partition for the pivot. With these modifications, the worst case of Quick sort has less chances to occur, but worst case can still occur if the input array is such that the maximum (or minimum) element is always chosen as pivot.
- Lower bound for comparison based sorting algorithms
- Which sorting algorithm makes minimum number of memory writes?
- Stability in sorting algorithms
- Iterative Quick Sort
- Find the Minimum length Unsorted Subarray, sorting which makes the complete array sorted
- Why Quick Sort preferred for Arrays and Merge Sort for Linked Lists?
- Can QuickSort be implemented in O(nLogn) worst case time complexity?
- Sort a nearly sorted (or K sorted) array
- Merge Sort for Linked Lists
- QuickSort on Singly Linked List
- Merge Sort
- Counting Sort
- QuickSort Tail Call Optimization (Reducing worst case space to Log n )