I don't think you should get worst case if you take the middle element as the pivot. What is the source of your claim?

The Gateway to Computer Science Excellence

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(n^{2})

**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(n ^{2}) irrespective of the selection of the pivot element?**

52,315 questions

60,436 answers

201,775 comments

95,252 users