edited by
903 views
0 votes
0 votes

Consider the following inputs:

1) 2 2 2 2 2 2 2

2) 1 2 3 4 5 6 7

3) 7 6 5 4 3 2 1

In all three cases, the worst-case time complexity of quicksort is O(n2)

 

My doubt is if I am taking the middle element as a pivot, then my recursive equation for the above three cases will become: T(n) = T(n/2) + O(n), right?

Can someone explain how we are saying worst-case time complexity for these three cases is O(n2) irrespective of the selection of the pivot element?

 

edited by

1 Answer

0 votes
0 votes
we get best case when we select median element as pivot and not middle element. fixing any position in the array as pivot may give worst case O(n^2).that is why randomised quick sort performs better coz u don't fix pivot position.

Related questions

0 votes
0 votes
1 answer
1
Purvi Agrawal asked Oct 13, 2018
3,762 views
In Quicksort let n/7​ th ​ smallest element is chosen using an O(n2​ ) algorithm as thepivot. Calculate the worst case time complexity of the algorithm.
3 votes
3 votes
1 answer
2
iarnav asked Jan 14, 2018
2,493 views
You have an array of n elements. Suppose you implement quick sort by always choosing the central element of the array as the pivot. Then the tightest lower bound for the...
3 votes
3 votes
3 answers
3
Sourajit25 asked Sep 3, 2017
1,649 views
"Quick sort has good cache performance" , Can anyone explain this statement.How is cache related to quick sort.I searched for this over the internet but could not find a ...
3 votes
3 votes
1 answer
4
SHALINI PORWAL asked Aug 10, 2017
1,379 views
When array is already sorted in reverse order then what will be the recurrence relation for number of swaps on array of n elements using quick sort?