61 61 votes Consider the Quicksort algorithm. Suppose there is a procedure for finding a pivot element which splits the list into two sub-lists each of which contains at least one-fifth of the elements. Let $T(n)$ be the number of comparisons required to sort $n$ elements. Then$T(n) \leq 2T(n/5) + n$$T(n) \leq T(n/5) + T(4n/5) + n$$T(n) \leq 2T(4n/5) + n$$T(n) \leq 2T(n/2) + n$ Algorithms gatecse-2008 algorithms sorting easy quick-sort + – Kathleen 24.8k views answer comment Share Follow Print See all 19 Comments 19 19 Comments reply Show 16 previous comments register_user_19 commented Oct 29, 2019 reply Follow flag Worst case:- if $i^{th}$ smallest or greatest is chosen $O(n^{2})$ (here i is constant eg. 5th largest is chosen as pivot) Best case:- if $n/4$ th smallest or largest $O(nlogn)$ 0 0 replyShare register_user_19 commented Oct 29, 2019 i edited by register_user_19 Oct 29, 2019 reply Follow flag if we chose pivot such that it divide array in $l:m $ ratio then, $T(n) \leq T(\frac{ln}{l+m}) +T(\frac{mn}{l+m}) + \Theta (n)$ NOTE:- worst case in simple quick sort is O(n^2), we can improve this, by selection algorithm (given in cormen 2nd edition pg 189 read this it hardly take not more than 1/2 hour) so we called randomized quicksort. worst case O(nlogn) 3 3 replyShare ROT commented Oct 26, 2024 reply Follow flag Another thing to note is the Randomized Quicksort may improve the performance, but the time complexity remains the same, Best and Avg case - $O(nlogn)$ and Worst case - $O(n^2)$ 1 1 replyShare Please log in or register to add a comment.
Best answer 56 56 votes $T(n) \leq T(n/5) + T(4n/5) + n$ One part contains $n/5$ elements and the other part contains $4n/5$ elements $+n$ is common to all options, so we need not to worry about it. Hence, the answer is option B. amarVashishth answered Nov 6, 2015 • edited Jun 20, 2021 by Lakshman Bhaiya 2 flags: ✌ Low quality (Anurag Prasad “Poor explanation”)✌ Edit necessary (sandeshrbhat24) amarVashishth comment Share Follow See all 10 Comments 10 10 Comments reply Show 7 previous comments Aayush Tripathi commented Aug 25, 2019 reply Follow flag worst case is T(n/5)+T(4n/5)+n because this is mentioned in the question "at least one-fifth of the elements" and the worst split is n/5 and 4n/5. Because of this A and D are not the answers because in A worst case is 2T(n/5)+n which is less than T(n/5)+T(4n/5)+n similarly D can't be the answer. C cannot be the answer because the equality never holds. Hope this helps. 4 4 replyShare shashankrustagi commented Jan 16, 2021 reply Follow flag It is directly from CORMEN 1 1 replyShare pavansan commented Jan 8, 2025 reply Follow flag @annie1234 remember sometimes overthinking also gives you penalty unless you will be in correct depth 3 3 replyShare Please log in or register to add a comment.
16 16 votes The answer is B. With 1/5 elements on one side giving T(n/5) and 4n/5 on the other side, giving T(4n/5). and n is the pivot selection time. Gate Keeda answered Dec 11, 2014 Gate Keeda comment Share Follow See all 2 Comments 2 2 Comments reply _xor_ commented Jun 5, 2015 reply Follow flag n is partition time . i think so . is it ??? 8 8 replyShare Sandeep Suri commented Jan 13, 2017 reply Follow flag Yes @xor 1 1 replyShare Please log in or register to add a comment.
10 10 votes Those who are confused between B and C .One thing is sure,If B is correct then C is also correct. i.e,if T(n)<=T(n/5)+T(4n/5)+n; implies T(n)<2T(4n/5)+n. Hence,here We will chosse TIGHTEST-BOUND i.e. Option:B Raas Star answered Sep 17, 2019 Raas Star comment Share Follow See all 2 Comments 2 2 Comments reply psych0 commented Dec 19, 2023 reply Follow flag helpful 0 0 replyShare js__ commented Jan 23 reply Follow flag psych0 Ok 0 0 replyShare Please log in or register to add a comment.
3 3 votes If you create two list containing 1/5th elements and in other it contains rest of the elements. If you go through the pivot elements it should give you recurrence relation T(n) = T(n/5) + T(4n/5) + n So option B is correct. Parth27 answered Mar 2, 2020 Parth27 comment Share Follow 0 reply Please log in or register to add a comment.
2 2 votes Answer: (B) — T(n)≤T(n/5)+T(4n/5)+n.Reason : pivot guarantees both parts have at least n/5 elements, so the two subproblems have sizes between n/5 and 4n/5. The worst split (for recurrence) is one of size ⌊n/5⌋ and the other ⌊4n/5⌋. Add linear-time partitioning work Θ(n), givingT(n)≤T(n/5)+T(4n/5)+Θ(n).With this bound the total cost is Θ(nlogn) since each level costs Θ(n) and depth is O(logn). SAURABH_SINGH_SRBH04 answered Oct 29, 2025 SAURABH_SINGH_SRBH04 comment Share Follow 0 reply Please log in or register to add a comment.