Suppose we have a O(n) time algorithm that finds median of an unsorted array.
Now consider a QuickSort implementation where we first find median using the above algorithm, then use median as pivot. What will be the worst case time complexity of this modified QuickSort.
(A) O(n^2 Logn)
(C) O(n Logn Logn)
Explanation: If we use median as a pivot element, then for each iteration it takes O(n) time to find median from given function and every time the array partitions in 2 subparts.
so the recurrence equation becomes.
T(n) = 2T(n/2) + O(n)