Prove that in the array P in procedure PERMUTE-BY-SORTING, the probability that all elements are unique is at least 1−1n.
Let Xi be an indicator random variable for the event that P[i] is not unique. P[i] being unique means that it holds a different value from the values found in P[1,…,i−1] which has at most i−1 distinct elements and so we have Pr{Xi}=E[Xi]≤i−1n3. Let X be a random variable for the event that P holds at least one duplicate element. This gives us
X=(X1∪X2∪⋯∪Xn)=X1+X2+⋯+Xn.We can then calculate
E[X]=E[n∑i=1Xi]=n∑i=1E[Xi]≤n∑i=1i−1n3=1n3n−1∑i=0i=1n3(n−1)n2 //(arithmetic series)=n−12n2≤1nAnd so the probability that all elements in P are unique is E[ˉX]=1−E[X]≥1−1n.