• retagged by
30,792 views
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 ________

6 Answers

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 $
• selected by
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.
7 7 votes
I think 2/25
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
• edited by
0 0 votes

In the worst case, the pivot element should be either the first or last element (either maximum or minimum).

A                        

or 

                        B


Required Probability=2/25=0.08.

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
Answer:
Position:
Show:

Related questions

65 65 votes
10 answers 10 answers
34.8k
34.8k views
Arjun asked Feb 7, 2019
34,766 views
Two numbers are chosen independently and uniformly at random from the set $\{1,2,\ldots,13\}.$The probability (rounded off to $3$ decimal places) that their $4\text{-bit}...
67 67 votes
8 answers 8 answers
28.2k
28.2k views
Arjun asked Feb 7, 2019
28,196 views
Suppose $Y$ is distributed uniformly in the open interval $(1,6)$. The probability that the polynomial $3x^2 +6xY+3Y+6$ has only real roots is (rounded off to $1$ decimal...
46 46 votes
12 answers 12 answers
36.8k
36.8k views
Arjun asked Feb 7, 2019
36,833 views
Consider a sequence of $14$ elements: $A=[-5, -10, 6, 3, -1, -2, 13, 4, -9, -1, 4, 12, -3, 0]$. The sequence sum $S(i,j) = \Sigma_{k=i}^j A[k]$. Determine the maximum of ...
13 13 votes
6 answers 6 answers
10.4k
10.4k views
Arjun asked Feb 16, 2024
10,432 views
Consider sorting the following array of integers in ascending order using an inplace Quicksort algorithm that uses the last element as the pivot.\begin{array}{|l|l|l|l|l|...