Monday, January 18, 2016

Online Hiring Problem

Problem

If there are n candidates, and we do not want to interview all candidates to find the best one. We also do not wish to hire and fire as we find better and better candidates.

Instead, we are willing to settle for a candidate who is close to the best, in exchange of hiring exactly once.

For each interview we must either immediately offer the position to the applicant or immediately reject the applicant.

What is the trade-off between minimizing the amount of interviewing and maximizing the quality of the candidate hired?

Code


Analysis

We analysis in the following to determine the best value of k that maximize the probability we hire the best candidate. In the analysis, we assume the index starts with 1 (rather than 0 as shown in the code).

Let $B_i$ be the event that the best candidate is the $i$-th candidate.
Let $O_i$ be the event that none of the candidate in position $k+1$ to $i-1$ is chosen.
Let $S_i$ be the event that we hire the best candidate when the best candidate is in the $i$-th position.

We have $Pr(S_i ) = Pr (B_i \cup O_i) = Pr(B_i) \cdot Pr(O_i)$ since $B_i$ and $O_i$ are independent events.

$Pr(S_i)  = \sum^n_{i=k+1} Pr(S_i)$
$ = \sum^n_{i=k+1} \frac{1}{n} \cdot \frac{k}{n-i}$
$ = \frac{k}{n} \sum^n_{i=k+1} \frac{1}{i-1}$
$ \leq \frac{k}{n} \cdot (\ln n - \ln k)$

Setting this derivative equal to 0, we see that we maximize the probability, i.e., when $k = n/e$, we have the probability at least $1/e$.


Reference
[1] Introduction to Algorithms, CLSR


No comments:

Post a Comment