50 50 votes Which one of the following is the recurrence equation for the worst case time complexity of the quick sort algorithm for sorting $n\;( \geq 2)$ numbers? In the recurrence equations given in the options below, $c$ is a constant.$T(n) = 2 T (n/2) + cn$$T(n) = T ( n - 1) + T(1) + cn$$T(n) = 2T ( n - 1) + cn$$T(n) = T (n/2) + cn$ Algorithms gatecse-2015-set1 algorithms recurrence-relation sorting easy quick-sort + – Misbah Ghaya 18.8k views answer comment Share Follow Print See all 7 Comments 7 7 Comments reply Show 4 previous comments usher commented Dec 8, 2024 reply Follow flag recurrence relation for quick sort:- best case/avg case : T(n) = 2T(n/2) + n because in best case the elements are divided equally, worst case : T(n) = T(n-1) + T(1) + cn worst case arrives when the array is already sorted in either ascending or descending order, thus making n^2 time complexity. 6 6 replyShare JHighlight commented Aug 10, 2025 i edited by JHighlight Aug 10, 2025 reply Follow flag @usher Sorted or reverse-sorted input with first/last element as pivot → worst case.But even an unsorted array can hit worst case if your pivot choice keeps ending up as min or max.https://gateoverflow.in/2048/gate-cse-2014-set-3-question-14 0 0 replyShare Sri28 commented Jan 26 reply Follow flag Can we say T(1) is for the first element? As n >= 2 given in question. 0 0 replyShare Please log in or register to add a comment.
Best answer 63 63 votes Correct Option: B Worst case for quick sort happens when $1$ element is on one list and $n-1$ elements on another list. Arjun answered Feb 11, 2015 • edited May 12, 2021 by soujanyareddy13 Arjun comment Share Follow See all 9 Comments 9 9 Comments reply Show 6 previous comments Regina Phalange commented Nov 2, 2017 reply Follow flag Option D means we are dividing the elements in half which is not the case for worst condition. 0 0 replyShare adeebafatima1 commented Oct 26, 2018 reply Follow flag can't say the given is wrong because asymptotically they are the same.Is it? 0 0 replyShare `JEET commented Jan 2, 2020 reply Follow flag For Worst Case correct Recurrences are: $\mathbf{T(n) = T(0) + T(n-1) + \theta (n)}$ which is the same as: $\mathbf{T(n) = T(n-1) + \theta (n)}$ The solution of this recurrence is $\mathbf{\theta (n)}$ Maybe the examiner have something to do with $\mathbf{n \ge 2}$ case. If this isn't the case, then the options are definitely wrong $\color{blue} {\text{According to Cormen and Wikipedia.}}$ 1 1 replyShare Please log in or register to add a comment.
3 3 votes If the pivot is chosen as the last position then there is a left recursive of size (n-1) or right recursive call of size 0. 1.Partition function->O(n) 2.T(n-1) time in left recursive call 3.T(1) time in right recursive call Recurrence relation: T(n-1)+T(1)+cn Option B is correct himanshu dhawan answered Apr 9, 2021 himanshu dhawan comment Share Follow 0 reply Please log in or register to add a comment.
0 0 votes Quick sort worst case time complexity is n^2, when the array is sorted or almost sorted then Quicksort algorithm runs in O(n^2) time. The recurrence relation for Quick sort worst case time complexity is T(n) = T(n-1) + T(1) + cn. Hence, B is Answer. manish_pal_sunny answered Aug 21, 2020 manish_pal_sunny comment Share Follow 0 reply Please log in or register to add a comment.