Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Probabilty based on quicksort partition

I have come across this question:

Let 0<α<.5 be some constant (independent of the input array length n). Recall the Partition subroutine employed by the QuickSort algorithm, as explained in lecture. What is the probability that, with a randomly chosen pivot element, the Partition subroutine produces a split in which the size of the smaller of the two subarrays is ≥α times the size of the original array?

Its answer is 1-2*α.

Can anyone explain me how has this answer come?Please Help.

like image 675
POOJA GUPTA Avatar asked Aug 25 '14 00:08

POOJA GUPTA


2 Answers

The other answers didn't quite click with me so here's another take:

If at least one of the 2 subarrays must be formula you can deduce that the pivot must also be in position formula. This is obvious by contradiction. If the pivot is formula then there is a subarray smaller than formula. By the same reasoning the pivot must also be formula. Any larger value for the pivot will yield a smaller subarray than formula on the "right hand side".

This means that formula, as shown by the diagram below:

enter image description here

What we want to calculate then is the probability of that event (call it A) i.e formula.

The way we calculate the probability of an event is to sum of the probability of the constituent outcomes i.e. that the pivot lands at formula.

That sum is expressed as:

enter image description here

Which easily simplifies to:

enter image description here

With some cancellation we get:

enter image description here

like image 111
Matt Harrison Avatar answered Nov 12 '22 06:11

Matt Harrison


The choice of the pivot element is random, with uniform distribution.

There are N elements in the array, and we will assume that N is large (or we won't get the answer we want).

If 0≤α≤1, the probability that the number of elements smaller than the pivot is less than αN is α. The probability that the number of elements greater than the pivot is less than αN is the same. If α≤ 1/2, then these two possibilities are exclusive.

To say that the smaller subarray is of length ≥αN, is to say that neither of these conditions holds, therefore the probability is 1-2α.

like image 11
Beta Avatar answered Nov 12 '22 07:11

Beta