60 60 votes An array of $25$ distinct elements is to be sorted using quicksort. Assume that the pivot element is chosen uniformly at random. The probability that the pivot element gets placed in the worst possible location in the first round of partitioning (rounded off to $2$ decimal places) is ________ Algorithms gatecse-2019 numerical-answers algorithms quick-sort probability one-mark + – Arjun 30.8k views answer comment Share Follow Print See all 8 Comments 8 8 Comments reply Show 5 previous comments Tushar Rana commented Jan 2, 2025 reply Follow flag @Shoaib_Ahmed it means the paritions are created in a way that 1 half contains no element and the other half have all the remaining elements. 0 0 replyShare SoloSword commented Jan 18 reply Follow flag worst case then either the max or the min is selected as pivot. thus 2 out of 25 . 0 0 replyShare jammypants commented Sep 14 reply Follow flag I feel doubtful about this approach because in the last step we are saying that the probability of (1/25)*(2/25) applies to all the 25 elements hence 25*(1/25)*(2/25) but the question states "in the first round of partitioning". All the 25 elements cannot be the worst pick in the first round 0 0 replyShare Please log in or register to add a comment.
Best answer 89 89 votes Worst case of quicksort, if pivot element is Minimum or Maximum. Total elements $= 25$ For worst case number of candidates $= 2$ $P = \frac{2}{25} = 0.08 $ Digvijay Pandey answered Feb 7, 2019 • selected Feb 7, 2019 by Rishi yadav Digvijay Pandey comment Share Follow See all 27 Comments 27 27 Comments reply Show 24 previous comments Jimmy5467 commented Aug 17, 2022 reply Follow flag n-3 is not because it will have 2 element on left hand side and to sort them we will need to call recursive function okay so if question was about told about asymptotic then the case which I told will come under worst case or not ?? 0 0 replyShare [ Jiren ] commented Sep 5, 2022 reply Follow flag In quick sort if the recursive equation is T(n) = T(n-k) + T(k) + n where k is constant then it will be asymptotically worst case 1 1 replyShare satyaAchar commented Oct 6, 2023 reply Follow flag @srestha worst case location means -→ last or first location→ which divide the array into 1|n-1 element.. so, if maximum or minimum is first pivot element then it should be palced in location 1st or last respectively.. therefore probability should be 2/25=0.08 thank you.. 3 3 replyShare Please log in or register to add a comment.
35 35 votes Quick sort puts the pivot element in its correct place after 1st iteration. The worst place the pivot element can be placed at is extreme left or extreme right because in that case the array is divided in the ratio 1:n-1 giving complexity of O(n Square). The pivot element will come to extreme left or right after 1st iteration if it's minimum or maximum.So pivot can be either minimum or maximum. So 2 out of 25 elements can be selected for pivot thus giving a probability of 2/25 equal to 0.08. Saurabh666 answered Feb 21, 2019 Saurabh666 comment Share Follow See 1 comment 1 1 comment reply ankit3009 commented Jan 12, 2021 reply Follow flag thanks for this explaination :) 0 0 replyShare Please log in or register to add a comment.
7 7 votes I think 2/25 vupadhayayx86 answered Feb 4, 2019 vupadhayayx86 comment Share Follow See all 4 Comments 4 4 Comments reply rosshan77 commented Feb 4, 2019 reply Follow flag 2/25 0 0 replyShare manisha11 commented Feb 4, 2019 reply Follow flag not 1/25 :( 0 0 replyShare vupadhayayx86 commented Feb 4, 2019 reply Follow flag Even I am not sure but if pivot element is first or last element then it can be worst case let's wait for answer key!! 0 0 replyShare manisha11 commented Feb 4, 2019 reply Follow flag the paper seemed easy but so many silly things :( :/ 0 0 replyShare Please log in or register to add a comment.
2 2 votes Quicksort performed worst if the position of pivot is either first or last. By the above discussion, I conclude that there are two worst-case positions first or the last position. Probability = 2/25=0.08 It can also understand as if we choose a minimum or maximum element as a pivot because if we choose minimum as pivot then it will be placed at a first position or if we choose the last element as pivot then it will be placed at the last position. So the probability is= 2/25=0.04 himanshu dhawan answered Apr 9, 2021 • edited Jun 23, 2024 by ꧁༒☬ĿọŗԀ 🆂🅷🅸🆅🅰☬༒꧂ himanshu dhawan comment Share Follow See 1 comment 1 1 comment reply -RahulKumar- commented Oct 5, 2023 reply Follow flag Small Correction: Probability = 2/25 = 0.08 0 0 replyShare Please log in or register to add a comment.
0 0 votes In the worst case, the pivot element should be either the first or last element (either maximum or minimum).A or BRequired Probability=2/25=0.08. paracetamol7mg answered Feb 26, 2025 paracetamol7mg comment Share Follow 0 reply Please log in or register to add a comment.
0 0 votes 2 choice 1st one is when pivot element get in 1 poistion and all n-1 element remains 2 nd when pivot get in last position and n-1 element remains so , P(E) = no . of favourable events / total no of events therfore , P(E) = 2/25 = 0.08 shivambidha answered Nov 30, 2025 shivambidha comment Share Follow See 1 comment 1 1 comment reply Jayvijay Chauhan commented Apr 23 i moved by Misbah Ghaya Apr 23 reply Follow flag Why not 3/25 we can put in middle which also leads to worst case (?? 0 0 replyShare Please log in or register to add a comment.