Problem:
In HIRE-ASSISTANT, assuming that the candidates are presented in a random order, what is the probability that you hire exactly twice?
Anlysis
Observation 1: You have to hire the first person interviewed because the assumed number 0 condidate is the worst.
Then the answer is: what's the probability that you have hired one person x with rank(x) and have to hire another condidate?
Observation 2: If rank(x) = n, then the conditional probability will be 0;
Observation 3: if rank(x)=n-1, the the conditional probalibity will be 1;
Observatoin 4: if rank(x)=n-2, then the conditional probability will be ?
....
if rank(x) = rx, then the maximum condidates of all the condidates with rank > rx, ie n, must come before other condidates with rank>rx.
permutate all the remaining condidates P(all) = (n-1)! C(target) = P(all)/P(n-rx)*P(n-rx-1) = (n-1)!/(n-rx)!*(n-rx-1)! = (n-1)!/(n-rx), p(target) = c(target)/P(n-1)=1/(n-rx);
Then add up all the numbers above each multipied by the probability of the condition.
1/n * E{ 1 / (n-rx) } (rx:1 ~ n-1);
Optimized method for calculating the conditional probability for each case above:
the case is as follows: we have (n-1) condidates left, order of (n-rx) must be ordered that the n will be the first of the (n-rx) condidates. Assume that we have arrived at a situation where all other condidates has been put in a position, we have to position the (n-rx) condidates one by one with equal probability so that the order we randomly put the (n-rx) condidates will not matter, so we just put the critical rank n condidates first, what's the probability of he/she be put in the first of the left (n-rx) positions? Of course it's 1/(n-rx);
The final result is 1 / n * E{ 1 / (n-rx) } (rx:1 ~ n-1); The same as the above.