Introduction
The secretary problem (sometimes called the marriage problem) is a famous algorithmic puzzle with applications in social decision making. I’ve taken the initial problem setup from another great article on the topic:
You are the HR manager of a company and need to hire the best secretary out of a given number N of candidates. You can interview them one by one, in random order. However, the decision of appointing or rejecting a particular applicant must be taken immediately after the interview. If nobody has been accepted before the end, the last candidate is chosen.
At this point, the following question is usually asked:
What strategy do you use to maximize the chances to hire the best applicant?
The well known solution to the problem (as goes to infinity) is as follows:
- Reject the first secretaries where is Eulers number, and note down the best out of this group as
- Hire the first secretary after that point that is better than
While this may be an interesting question, it falls short of the real world scenario we are trying to model here in our opinion. If the secretaries are randomly distributed, the second best secretary out of the should also be a pretty good hire, and same for the third best. In fact, a strategy that picks the best secretary 10 percent of the time and the worst secretary every other time should really be deemed worse than one that picks the best secretary 9 percent of the time and the second best the other 91 percent.
Our previous musings lead to the idea of trying to maximize the best secretary in expectation, where the best secretary of the group has the highest value of , the second best , and so on until the worst secretary with a score of 1. This may yield different results to the more famous setup where the probability of picking the best secretary is maximized. We will call this the Discrete Expected Secretary Problem.
Solution to the “Discrete Expected Secretary Problem”
Formally, we will consider a set of secretaries with distinct scores from 1 to , and order them randomly. We will use the strategy of passing on some fixed number secretaries then picking the next one better than all those we passed on, with being the optimal value for highest expected return.
If we can write the expected value in terms of , i.e.
then we can simply differentiate with respect to and find the max by setting the derivative equal to zero. Let’s try that. From here on, represents the number of secretaries we reject in part one of the algorithm.
Expectation Calculation
To tackle this problem, we will use the law of total expectation, and partition our possibilities based on the score of , the best secretary from the initial rejected group. Notice that this value must be at least , since the initial group has secretaries:
From here, notice that calculating is relatively easy.
- If , then the best secretary was in the rejecting group, and we are forced to choose the last secretary in the list of . The last secretary is distributed randomly between the worst and second best in this case (since the best is in the initial ), so the expected value is
- If , then the best secretary was not in the rejecting group, and any secretary better than has the same probability of being the first one to be found after all rejections. As a result, the expected value is the average of all of their scores, or
These thoughts lead us to the new equation of:
We can again simplify, since the probability that (i.e. the best secretary of the first is ) is simply the probability that the best secretary (with score ) is in the first . Since everyone is randomly distributed, this occurs with probability :
We now have:
What’s left is to determine in the other cases, and turn this whole thing into closed form. Here we will turn to combinatorics.
Since the secretaries are in a random order, all orderings have the same probability. As a result, we can find for any arbitrary by counting how many orderings have as the best secretary in the first over the total number of secretaries.
Note that for some arbitrary exactly when:
- The th secretary is in the first
- the other secretaries in the first are worse than secretary .
Let’s count the number of valid orderings
The only difference between a valid ordering and an arbitrary ordering of the secretaries is that for an arbitrary ordering, we can choose any subset to be in the first , and we can put element anywhere:
From here we can finally calculate the prbability as
From here we can finally fully write the expected value of the secretary chosen from Equation (2) and (3) for an arbitrary stopping point as
Luckily, the result simplifies nicely into
Click here for the full proof (slightly involved)
Note that in every assignment, must be a value between and . As a result, the sum of probabilities of for between and must add to 1. We have that:
moving around some terms, we have that:
Click here for the full subproof of moving around terms
Via a similar process where we reject the first secretaries, we arrive at
Click here for fully worked out similar process
Let’s consider rejecting the first secretaries, and finding the probability that secretary is the best secretary in this group. We can count the number of ways this happens in the same way as equation 9 to yield:
Again, since the sum of these probabilities from to covers all possible top rejecting people, we have that:
This directly yields the result, or
Putting this all together, we get:
Using the chain/quotient rules, the derivative with respect to works out to be
Finally, we can set this to zero to and solve for to achieve a solution of
Click here for fully worked out maxima calculation
Success! we now know that we should only reject the first secretaries, then pick the next one that is greater than all those we rejected. If this isn’t a whole number, we can simply pick the closest integer to 
Visualizations/Intuition
In the original version of the problem, we had to reject the first , or percent of secretaries before beginning the next stage. This means that percent of the time, the top secretary is in the rejection group and the algorithm fails! When optimizing for only the top secretary, we have to pick a random secretary with a relatively low expected score over 1/3 of the time.
This is more OK when the only goal is to try and maximize the probability of the highest secretary, but severely punishes our formulation where getting the second best secretary or third best is also a win.
Here we visualize the expected value for picking the rejection number at 1 through 100 for as well as the probability of picking the best secretary. As predicted, the highest expected value is at , with an expected secretary score of 91.405, which is pretty good!! At this value, the probability of picking the best secretary is only 21 percent, as opposed to the 36 percent which occurs if we wait 36 people instead of 9. Since we only wait for the first 9 secretaries, our algorithm “fails” and is forced to pick the last secretary only percent of the time.
A nicer formulation of the expected value is as follows:
Here, notice that if is too big, the first negative term will reduce the epxected value, while if is too small, the second negative term will reduce the expected value.