Secretary Problem
🛑 ALL INFORMATION CLICK HERE 👈🏻👈🏻👈🏻
Secretary Problem
Table of contents
Exit focus mode
Article
01/31/2019
12 minutes to read
Light
Dark
High contrast
Light
Dark
High contrast
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Suppose you want to hire a secretary. You have a pool of 100 applicants and you interview one applicant per day. After each interview, you must immediately decide to hire the current applicant or not. If you don’t hire an applicant, you can’t call her back. You don’t have time to interview all 100 candidates, so what algorithm can you use to maximize your chance of selecting the best applicant?
What I’ve just described is one example of the Secretary Problem. Solutions to the Secretary Problem have many important uses. For example, in machine learning, it’s often necessary to come up with some approach for stopping training in a way to optimize the probability of selecting the best prediction model.
The Secretary Problem is part of a larger class of problems sometimes called best choice problems, and also part of what are called optimal stopping problems. To the best of my knowledge, a description of the Secretary Problem (in a slightly different form) was first published in Scientific American magazine in 1960. There are dozens of interesting variations of the problem.
In this article I’ll show you how to tackle the Secretary Problem using what’s called the 1/e stopping rule. A good way to see where this article is headed is to examine the demo program in Figure 1 . I coded the demo using C#, but you shouldn’t have any trouble refactoring the code to another language if you wish.
Figure 1 Secretary Problem Demo Program Run
This article assumes you have at least intermediate programming ability, but doesn’t assume you know anything about the Secretary Problem. The complete source code for the demo program is presented in this article, and you can also get the source from the accompanying code download.
It can be mathematically proved that, subject to certain conditions, you can theoretically maximize the probability of selecting the best applicant in the Secretary Problem by using what’s called the 1/e rule or algorithm. In the context of the Secretary Problem, the term Candidate means the best applicant seen at a given point in time. I capitalize the word Candidate to emphasize that the word has a different meaning than in normal English, where a candidate and an applicant are essentially synonymous.
In the following explanation, N represents the total number of applicants, and e represents Euler’s constant, which is approximately 2.71828. In words, the 1/e rule is, “Skip over the first N / e applicants, but track the best Candidate. Then hire the first Candidate who appears. If no new Candidate appears after the first N / e applicants have been skipped, then fail and hire nobody.”
A concrete example should make the algorithm clear. The 1/e stopping algorithm is illustrated graphically in Figure 2 . Suppose you have 10 applicants. Each applicant has (unknown to you until after you interview them) a rating between 0.0 and 9.0, where higher values are better. The applicants’ ratings are:
Figure 2 The 1/e Algorithm for the Secretary Problem
Applicant 0 has a rating of 5.0 and will be interviewed first; applicant 1 has a rating of 2.0 and will be interviewed second; and so on. The best applicant is person 8 with a rating of 9.0.
The number of applicants to skip is N / e = 10 / 2.71828 = 3.6788, which is 3 if truncated, and 4 if rounded. As it turns out, as long as N is not very small it makes very little difference whether you truncate or round. Suppose you truncate to 3.
You interview applicant 0 and find she has a rating of 5.0, so she becomes the Candidate because she has the best rating seen (so far, the only rating seen). Next, you interview applicant 1 and find they have a rating of 2.0 so they don’t become the Candidate because their rating isn’t better than 5.0. You interview applicant 2 and find a rating of 7.0 and they become the new Candidate. At this point you’ve interviewed the first N / e = 3 applicants so you’re now ready to hire the first new Candidate who appears.
You interview applicant 3 and find a rating of 1.0 so they don’t become the Candidate. You interview applicant 5 and find a rating of 0.0 (Ouch! I’ve worked with this person) so they’re not the Candidate, either. You interview applicant 6 and find a rating of 8.0. This is the highest rating seen so they become the Candidate, and because you’re past the first N / e applicants, you immediately hire applicant 6.
Notice that the 1/e algorithm did not find the best applicant in this example, but did find the second best applicant. If you use the 1/e algorithm for the Secretary Problem, the probability that you’ll select the best applicant from N applicants is approximately 1 / e = 1 / 2.71828 = 0.3679.
To create the demo program, I launched Visual Studio and made a new C# console application program named SecretaryProblem. The demo program has no significant .NET dependencies, so any version of Visual Studio will work. After the template code loaded, in the Solution Explorer window, I right-clicked on file Program.cs and renamed it to the more-descriptive SecretaryProblemProgram.cs and Visual Studio automatically renamed class Program for me. At the top of the Editor window, I removed all using statements that referenced unnecessary namespaces, leaving just the one reference to the top-level System namespace.
The demo program has two parts. The first few lines in the Main method illustrate the 1/e algorithm when applied to a specific Secretary Problem example with 10 applicants. The second part of the demo illustrates a simulation where the 1/e algorithm is run 10,000 times with 100 applicants.
The key lines of calling code for the first part of the demo are:
A problem is set up by defining applicants as an array of type double where the index represents an applicant ID, and the cell value represents an applicant’s rating. The basic version of the Secretary Problem assumes that all applicant ratings are different, so there can be no ties.
The program-defined Select method accepts a rating array and uses the 1/e algorithm to find and return the index of the selected applicant. The Select method has a lot of WriteLine statements that print progress, as shown in Figure 1 .
The key lines of calling code (with minor editing for readability) for the second part of the demo are:
The program-defined Simulation method accepts a fixed number of applicants. An alternative design is to allow the simulation to randomly select the number of applicants in each trial. Behind the scenes, the Simulation method loops, calling a non-verbose version of the Select method, while keeping track of the number of times the best applicant was selected.
The definition of the Select method begins as:
The number of applicants is determined by the number of cells in the ratings array. You could make this explicit by passing an additional parameter N to Select. Variable numSkip is the number of initial applicants to skip over while tracking the best applicant so far. If you wanted to round instead of truncate, you could write:
Variable candidate is the best applicant seen at any point in time during the hiring process and variable bestRating is the rating associated with the Candidate. The two variables are initialized to the values of the first applicant, rather than using dummy values such as -1 and -1.0, respectively.
Variable rating represents the rating of the current applicant, and is just for readability. Boolean variable readyToHire is false when processing the first numSkip-1 applicants, then set to true afterward.
The body of method Select is short and relatively simple:
The method walks through each applicant in the ratings array. For each applicant, the current applicant becomes the Candidate if the current applicant’s rating is greater than the best (highest) rating seen. When Boolean variable readyToHire is false, Candidates are identified but not returned. When readyToHire is true, the first available Candidate found is returned, corresponding to an immediate hire in the Secretary Problem.
An alternative design is to use two loops instead of a single processing loop, where the first loop iterates over the applicants to skip, and the second loop identifies the first available Candidate:
It’s possible that no new Candidate will appear after the first numSkip applicants. For example, suppose you have eight applicants with ratings (7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0, 0.0). Variable numSkip would be set to 8 / 2.71828 = 2. After the first two applicants are interviewed, the best rating would be 7.0 and none of the remaining six applicants would be identified as a Candidate. Method Select returns a dummy value of -1 when no Candidate is found.
In high-level pseudo-code, the Simulation method is:
The definition of method Simulate begins with:
As described earlier, applicants and their ratings are stored in an array where the array index is the applicant ID, and the cell value is the rating. The value in cell 0 is set to 0.0, the value in cell 1 is set to 1.0, and so on. For example, if there are N = 100 applicants, the applicant IDs are 0 through 99 and the optimal rating is 99.0.
The main processing loop in method Simulation is:
A program-defined method named Shuffle rearranges the ratings in-place using the Fisher-Yates mini-algorithm:
The Fisher-Yates algorithm is often used in machine learning and simulation programs to shuffle the values in a linear collection. Many programming languages, for example Python and R, include a built-in shuffle method as part of their standard function library. Here, the program-defined Shuffle method assumes the existence of a class-scope Random object:
After the ratings are randomized, the processing loop in method Simulation calls the Select method to pick an applicant using the 1/e algorithm, and then the selected applicant is checked to see if they’re the optimal applicant.
When checking for the optimal candidate, two floating-point values are compared for exact equality:
This approach is usually a bad idea because some floating-point values are stored only as approximations, to a fixed number of decimal points. The compare-for-exact-equality approach is OK in this particular example, but in general you’d want to compare for very closeness rather than exact equality.
The information presented in this article is based primarily on the 2003 research paper, “Analysis of Heuristic Solutions to the Best Choice Problem,” by W. Stein, D. Seale and A. Rapoport. You can find the paper in PDF format in several places on the Internet. The paper presents a mathematical analysis of the 1/e rule and two additional rules.
The “candidate count” rule arbitrarily selects the nth Candidate. For example, if n = 3, the third Candidate encountered will be selected. In the example presented at the beginning of this article, where the applicants and ratings are (5.0, 2.0, 7.0, 1.0, 4.0, 0.0, 8.0, 3.0, 9.0, 6.0), the third Candidate is applicant 6 with a rating of 8.0, which coincidentally is the same as the 1/e rule. As it turns out, the candidate count rule is not very effective.
The “successive non-candidate” rule selects the first Candidate seen after observing k non-Candidates. For example, suppose k = 3. For the example applicants and ratings, the first k non-Candidates have ratings 2.0, 1.0 and 4.0. The next Candidate is applicant 6 with a rating of 8.0, which again is, coincidentally, the same as the 1/e rule. The successive non-candidate rule turns out to work quite well.
Once you become familiar with the general structure of the Secretary Problem, you’ll find quite a few scenarios where the key principles are relevant. Whenever you’re faced with a programming task that involves an uncertain stopping point, the ideas of the Secretary Problem might be useful.
Dr. James McCaffrey works for Microsoft Research in Redmond, Wash. He has worked on several Microsoft products including Internet Explorer and Bing. Dr. McCaffrey can be reached at jammc@microsoft.com .
Thanks to the following Microsoft technical experts who reviewed this article: Chris Lee and Kirk Olynyk
How to Cite This Entry: Secretary problem. Encyclopedia of Mathematics. URL: http://encyclopediaofmath.org/index.php?title=Secretary_problem&oldid=50947
This article was adapted from an original article by M. Hazewinkel (originator), which appeared in Encyclopedia of Mathematics - ISBN 1402006098. See original article
best choice problem, marriage problem
One of the best known optimal stopping problems (see also Stopping time ; Sequential analysis ).
A manager has the problem of selecting a secretary from a group of n girls. He interviews them sequentially, one at a time, and, at each moment, can hire that particular girl. Rejected girls cannot be recalled. At each stage he knows how the present girl ranks with respect to her predecessors, but he does not know, of course, how she compares with the girls yet unseen. A rule is asked for that maximizes the chance of actually selecting the best girl.
The solution (for large n ) is to examine and reject p girls and to subsequentially choose the first girl that is better than all these p girls, where the natural number p is chosen such that the fraction p n is as close as possible to e − 1 (with e the base of the natural logarithms; see also e (number) ). More precisely, p should be chosen to maximize the expression
Seen as a betting game, the secretary problem is the same as the game of googol (see also Googol ).
Y.S. Chow, H. Robbins, D. Siegmund, "The theory of optimal stopping" , Dover, reprint (1991) (Original: Houghton–Mifflin, 1971)
T.S. Ferguson, "Who solved the secretary problem?" Statistical Science , 4 (1989) pp. 282–296
P.R. Freeman, "The secretary problem and its extensions: a review" Internat. Statist. Review , 51 (1983) pp. 189–206
I was, to put it mildly, something of a mess after my last relationship imploded. I wrote poems and love letters and responded to all of her text messages with two messages and all sorts of other things that make me cringe now and oh god what was I thinking.
I learned a few things, though, like when you tell strangers that your long-term relationship has just been bulldozed as thoroughly as the Romans salted Carthage, they do this sorta Vulcan mind-meld and become super empathy machines. Even older folk, who usually treat me not exactly as a non-person but something sorta like it. At the time, I had this gruff, Russian psychiatrist I’d see once a month, and he was all like, “Been there, man. Have some Diazepam and relax.” — except, you know, he said it in Russian-accented doctorspeak.
This was surprising to me then but isn’t now. Live long enough and you’ll have your heart thrashed about a fair bit, along with the rest of you. Mention heartbreak and everyone has their own private story — maybe more than one. It’s not Vietnam. They’ve been there and they understand.
I sometimes wonder — if I could go back in time, what could I say to comfort my former self? What can you say to someone that will pull them out of the throes of hormone-induced suffering? Probably nothing. The remarkable thing about words is not that they sometimes move people, but that they so seldom do.
Still, I think I’d say something like, “My boy, evolution is a motherfucker and you need a new woman in your life.” He would probably protest that women were the problem and that he’s pretty sure the last thing he needs is another one. Then, I would let out the most condescending sigh imaginable, the sort of sigh that says I-have-unimaginable-wisdom-born-of-experience-and-am-from-the-future, and say, “Not that sort of woman. You need the Queen. You need mathematics –”
“Let me tell you about the secretary problem.”
Consider the plight of John. John’s 25. He lives in Utah and likes country music, hunting, and four wheelers. You probably see where I’m going with this. That’s right, ladies and gentlemen. John is gay.
The recent supreme court decision overturning gay marriage in Utah has him thinking. He’d like to settle down one day — maybe adopt a child with the right man. He has a couple short-term relationships going on right now, but married to Bruce or Sidney? No way.
How can he guarantee that he snags, if not Mr. Right, at least Mr. Close Enough? He figures he ought to date at least a few different men, and then… what?
Imagine he meets this guy, Jim. They make out at a party, hang out a few times, and realize that they’re kinda already dating, and decide to label it by making it Facebook official. Things progress. John asks Jim to move in with him.
Then there’s a snag. Valentine’s Day rolls around, and John finds himself, at the last minute, at Walmart, looking to pick up some chocolate and cheap Champagne, wondering, “Is this really what love feels like?”
What should John do in such a situation? Should he next Jim and take his chances on the dating market? Or should he settle and settle down?
John’s predicament is an example of the secretary problem — so named because we can imagine the same situation, except instead of a man searching for a husband, it’s a man interviewing potential secretaries. When is the candidate good enough? What’s the stopping criteria?
We can abstract away the specifics of John’s plight and formalize the problem. Let’s consider each man that John dates as an integer — the integer representing his “husbandness factor.” Thus, a sequence of lovers like ( S i d n e y , B r u c e , J i m , T o d d , K e i t h , B r u n o , T e r r e n c e , C e c i l , N i g e l ) ( S i d n e y , B r u c e , J i m , T o d d , K e i t h , B r u n o , T e r r e n c e , C e c i l , N i g e l ) would translate to the integer sequence ( 1 , 3 , 7 , 5 , 8 , 3 , 1 , 9 , 4 ) ( 1 , 3 , 7 , 5 , 8 , 3 , 1 , 9 , 4 ) .
This problem would be trivial — just pick the max element — if it weren’t for two properties.
We can think of it visually as a machine which is fed a tape of integers. It has two actions: it can either stop or it can consider the next integer. The machine’s objective is to stop on the highest integer.
At the heart of the secretary problem is conflict. Do I reject the current possibility in hopes of landing something better if I keep looking, or do I stick with what I have?
The following
Nasty And Denise Seks In Foot
Shein Lingerie
3d Futa Overwatch