randomized quicksort: probability of two elements comparison?
Posted
by bantu
on Stack Overflow
See other posts from Stack Overflow
or by bantu
Published on 2010-05-01T16:42:10Z
Indexed on
2010/05/01
16:47 UTC
Read the original article
Hit count: 350
I am reading "Probability and Computing" by M.Mitzenmacher, E.Upfal and I have problems understanding how the probability of comparison of two elements is calculated.
Input: the list (y1,y2,...,YN) of numbers. We are looking for pivot element. Question: what is probability that two elements yi and yj (j>i) will be compared?
Answer (from book): yi and yj will be compared if either yi or yj will be selected as pivot in first draw from sequence (yi,yi+1,...,yj-1,yj). So the probablity is: 2/(y-i+1).
The problem for me is initial claim: for example, picking up yi in the first draw from the whole list will cause the comparison with yj (and vice-versa) and the probability is 2/n.
So, rather the "reverse" claim is true -- none of the (yi+1,...,yj-1) elements can be selected beforeyi or yj, but the "pool" size is not fixed (in first draw it is n for sure, but on the second it is smaller).
Could someone please explain this, how the authors come up with such simplified conclusion?
Thank you in advance
© Stack Overflow or respective owner