Randomized quicksort is an extension of quicksort where the pivot is c...
Randomized quicksort has expected time complexity as O(nLogn), but worst case time complexity remains same. In worst case the randomized function can pick the index of corner element every time.
View all questions of this test
Randomized quicksort is an extension of quicksort where the pivot is c...
Worst Case Complexity of Randomized Quicksort
Quicksort is a popular sorting algorithm that follows the divide-and-conquer approach. It works by selecting a pivot element and partitioning the array into two subarrays, one with elements smaller than the pivot and another with elements greater than the pivot. This process is recursively applied to the two subarrays until the entire array is sorted.
In the case of traditional quicksort, the pivot is typically chosen as either the first, last, or middle element of the array. However, in randomized quicksort, the pivot is chosen randomly from the array.
Best Case Complexity:
The best case complexity of randomized quicksort occurs when the pivot element always divides the array into two equal halves. In this scenario, the array is partitioned into two subarrays of roughly equal size, and the recursive quicksort process continues until the entire array is sorted.
In this case, the time complexity is O(n log n), where n is the number of elements in the array. This is the same as the average case complexity of traditional quicksort.
Worst Case Complexity:
The worst case complexity of randomized quicksort occurs when the pivot element is always chosen as the minimum or maximum element of the array. This can happen in rare cases, especially when the random number generator used to select the pivot is biased.
In this scenario, the partitioning process results in one subarray with n-1 elements and another subarray with no elements. Consequently, the recursive quicksort process only reduces the problem size by one element in each iteration.
As a result, the time complexity becomes O(n^2), where n is the number of elements in the array. This is worse than the worst case complexity of traditional quicksort, which is O(n log n).
Conclusion:
The worst case complexity of sorting n numbers using randomized quicksort is O(n^2). However, it is important to note that the probability of encountering this worst-case scenario is extremely low in practice. Randomized quicksort is generally considered to be an efficient sorting algorithm with an average case complexity of O(n log n).
To make sure you are not studying endlessly, EduRev has designed Computer Science Engineering (CSE) study material, with Structured Courses, Videos, & Test Series. Plus get personalized analysis, doubt solving and improvement plans to achieve a great score in Computer Science Engineering (CSE).