4 ms·
Another neat way to look at it--the probability of any given element is the probability of it being swapped in times the probability it isn't swapped out in eac
by evo 16y ago
Another neat way to look at it--the probability of any given element is the probability of it being swapped in times the probability it isn't swapped out in each successive item. For A[p]:
(1/p)((p)/(p+1))((p+1)/(p+2)) ... ((n-1)/n))
e.g. the fifth element's probability in an eight-element list is
1/5 * 5/6 * 6/7 *7/8
Since the numerator of each successive term cancels out the denominator of the last, the product is always 1/n.