edited by
508 views
5 votes
5 votes

If we have an array of size $\mathrm{N}$ with only $3$ different values for its elements, what is the probability that the first partition results in a completely sorted array? Assume there are an equal number of each element in the array.

  1. $1 / 2$
  2. $1 / 3$
  3. $1 / 4$
  4. $2 / 3$
edited by

1 Answer

7 votes
7 votes
If the median value gets picked as the pivot, the array will be in sorted order after only a single pivot. If the smallest or largest gets picked, we're not quite done.

Probability of choosing median $= 1/3$ since there are just three types of values in equal proportion.
edited by
Answer:

Related questions