I am reading “Probability and Computing” by M.Mitzenmacher and E.Upfal. I am having problems understanding how the probability of comparison of two elements is calculated.
Input: sorted list (y1,y2,…,yN) of numbers. We are looking for pivot element (randomly). 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/(j-i+1).
The problem for me is the 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 before yi 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 how the authors come up with such a simplified conclusion?
Edit1: some good soul polished my post, thank you :-).
Edit2: the list is sorted initially.
The answer given by the authors is correct, though I still don’t see how they jumped to the conclusion that easily and fast.
Let denote by L=j-i+1. Actual values of j and i don’t matter here, what matters is L. Let also denote by P(N,L) probability of comparing yi and yj element from ordered sequence of numbers of size N.
Facts:
This sum looks ugly, but after two tests it appeared that the P(N,L) is probably equal to 2/L. Let’s check it out:
And since L=j-i+1, we get 2/(j-i+1).