in Algorithms edited by
1,558 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)
in Algorithms edited by
1.6k views

4 Comments

It should be O(nlogn) in worst case because, selecting median as pivot means it will be always  placed at the middle after applying partition algorithm.
0
0
B is the correct option

Because for every split occur at the middle .
0
0
what is that means[ Pivot is the median of set of 3 elements ].
0
0

4 Answers

1 vote
1 vote
Worst case would be Θ($n^2$) because input array given is already sorted.
reshown by

2 Comments

i think O(nlogn) is right answer....
0
0
1 vote
1 vote
B should be the correct option.
1 vote
1 vote
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