edited by
1,624 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

5.2k
views
2 answers
1 votes
Shubhanshu asked Dec 1, 2018
5,184 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 ... preorderedness of the input. But in case of Quick sort it act as disadvantage.
1.6k
views
1 answers
10 votes
mohit chawla asked Nov 14, 2016
1,616 views
There are many variations of Quicksort. We may choose the pivot for each partition step in various ways. There are various strategies for partitioning an array segment into one subpartition of ... 3, 1c) 5, 4, 3, 3, 5d) 1, 4, 1, 3
659
views
0 answers
0 votes
Abhishek Kumar 38 asked Dec 19, 2018
659 views
Which of the following sorting algorithm represented by above code?
894
views
1 answers
2 votes
aambazinga asked Dec 15, 2018
894 views
An array of size n is known to be sorted except for the 1st k elements and the last k elements, where k is a constant. which of the following algorithm is the best ... in average case and O(k^2) in the worst case. what's wrong in that?