edited by
1,539 views
3 votes
3 votes
Consider a scenario of modified quick sort, where we have given an input sorted array A[1 .. . n], all elements of array are distinct and n >=3. Pivot is the median of set of 3 elements [First element, middle element, and last element]. What will be worst case time complexity of modified quick sort?

a.O($n^{2}$)
b.O(nlogn)
c.O($n^{2}$logn)
d.O(nloglogn)
edited by

4 Answers

1 votes
1 votes
Worst case would be Θ($n^2$) because input array given is already sorted.
reshown by
1 votes
1 votes
Option B is the correct answer.

lets consider an array 1,2,3,4,5

according to the question median of an array = median(1,3,5)= 3.

so the array is divided into almost equal halves and for that time complexity would be O(nlogn)
0 votes
0 votes
option B) O(nlogn) is correct , because everytime array is divided into almost equal parts.

Related questions

1 votes
1 votes
2 answers
1
Shubhanshu asked Dec 1, 2018
5,040 views
Is Quick sort an adaptive sorting Algorithm? I think no. Because as per the definition given in the Wikipedia is that A adaptive sorting Algorithm is one who takes the ad...
0 votes
0 votes
0 answers
3
Abhishek Kumar 38 asked Dec 19, 2018
611 views
Which of the following sorting algorithm represented by above code?