Match Maker

You have 10 men and 10 women. Each man is married to one of the women (and no woman is married to more than one man). However, you don't know who is married to who; your job is to determine this.

To do this, you make several attempts. In an attempt, you match each man with some woman such that each woman is paired with exactly one man. Then, you are told which couples you guessed correctly. If you haven't guessed all couples correctly, you make another attempt. You repeat this until you get all correct.

Because you don't know anyone, your strategy is simple. You pick the couples at random. When you get a couple correct, in all future attempts, you will pair up that couple. For the other incorrect couples, you guess them at random again; this might mean you repeat a couple you previously attempted.

On average, how many attempts does it take for you to get all couples correct?


The answer is 10.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

4 solutions

Ivan Koswara
Aug 12, 2016

Relevant wiki: Expected Value - Problem Solving

We'll be for a bumpy ride, involving expected value of something seemingly unrelated and the fundamental theorem of algebra.


Let p ( n , k ) p(n,k) be the probability that if we take a random permutation of n n elements, then exactly k k of them are on their original positions. We can prove that p ( n , k ) = D n k k ! ( n k ) ! p(n,k) = \frac{D_{n-k}}{k!(n-k)!} where D k D_k is the number of derangements of k k elements, but it's not important. The only important fact is that k = 0 n p ( n , k ) = 1 \displaystyle \sum_{k=0}^n p(n,k) = 1 , because they are mutually exclusive and exhaustive: any permutation of n n elements must have some amount k k of them in their original positions, and this k k must satisfy 0 k n 0 \le k \le n .

Lemma 1: k = 0 n p ( n , k ) k = 1 \displaystyle \sum_{k=0}^n p(n,k) \cdot k = 1 .

To prove this, we will use double counting. Suppose we take a random permutation of n n elements. What is the expected number of elements that are in their original positions?

On one hand, this can be computed as ( ( probability of $k$ fixed elements ) k ) \sum ((\text{probability of \$k\$ fixed elements}) \cdot k) ; this is the formula for expected value, where you multiply each value with the probability of getting it, and then sum over all possible values. But we know that the only possible values are 0 , 1 , 2 , , n 0, 1, 2, \ldots, n , and the probability of having k k fixed elements is p ( n , k ) p(n,k) by definition. Thus we obtain k = 0 n p ( n , k ) k \displaystyle \sum_{k=0}^n p(n,k) \cdot k , which is the left hand side of the equation.

On the other hand, we can use linearity of expectation to compute this value. Note that any particular element will be in its original position exactly 1 n \frac{1}{n} of the time, so the expected value of this particular element being in its original position is 1 n \frac{1}{n} . Because expectation is linear even if it's not independent, we can sum over all n n elements; the expected number of elements that are in their original positions is n 1 n = 1 n \cdot \frac{1}{n} = 1 , the right hand side of the equation.

But these two methods compute the same number, so they must be equal. This completes the proof of the lemma.


Now, we will go to the actual problem. Let E ( n ) E(n) be the expected number of attempts, given there are n n men and n n women.

Claim: E ( n ) = n E(n) = n for all n n .

We will prove this by strong induction on n n . The base case is n = 0 n = 0 , where we don't have anyone; then we don't need to do anything at all.

Now, we have the following recurrence relation:

E ( n ) = 1 + k = 0 n p ( n , k ) E ( n k ) \displaystyle E(n) = 1 + \sum_{k=0}^n p(n,k) \cdot E(n-k)

The idea is that we may assume the men to be positions, and the women to be elements; now, pairing them randomly is equivalent to taking a random permutation. A man and a woman make a couple exactly when an element is in its original position. Thus, the probability that we will get exactly k k couples correct is simply p ( n , k ) p(n,k) , again by definition. The 1 1 is to count this first attempt. When we have k k couples correct, we can just remove them; now we have the exact same problem, but with only n k n-k men and n k n-k women, which by definition needs E ( n k ) E(n-k) attempts on average; thus, p ( n , k ) E ( n k ) p(n,k) \cdot E(n-k) is the weighted expected number of attempts when k k couples are matched. Summing over all k k exhausts all possibilities, giving the formula.

Now, by induction hypothesis, E ( n k ) = n k E(n-k) = n-k for all k 1 k \ge 1 . This leaves us with:

E ( n ) = 1 + p ( n , 0 ) E ( n ) + k = 1 n p ( n , k ) ( n k ) \displaystyle E(n) = 1 + p(n,0) \cdot E(n) + \sum_{k=1}^n p(n,k) \cdot (n-k)

Another important thing to note is that p ( n , n ) > 0 p(n,n) > 0 , because p ( n , n ) p(n,n) is the probability that all n n elements are in their correct positions, which is simply 1 n ! > 0 \frac{1}{n!} > 0 .

Remember that k = 0 n p ( n , k ) = 1 \displaystyle \sum_{k=0}^n p(n,k) = 1 . We have p ( n , 1 ) , p ( n , 2 ) , p ( n , 3 ) , , p ( n , n 1 ) 0 p(n,1), p(n,2), p(n,3), \ldots, p(n,n-1) \ge 0 (probabilities are always non-negative) and p ( n , n ) > 0 p(n,n) > 0 . This means:

p ( n , 0 ) = 1 k = 1 n 1 p ( n , k ) p ( n , n ) 1 0 p ( n , n ) < 1 0 0 = 1 \displaystyle\begin{aligned} p(n,0) &= 1 - \sum_{k=1}^{n-1} p(n,k) - p(n,n) \\ &\le 1 - 0 - p(n,n) \\ &< 1 - 0 - 0 \\ &= 1 \end{aligned}

Since p ( n , 0 ) < 1 p(n,0) < 1 , this means p ( n , 0 ) E ( n ) p(n,0) \cdot E(n) doesn't fully cancel with E ( n ) E(n) . Thus the equation E ( n ) = 1 + p ( n , 0 ) E ( n ) + k = 1 n p ( n , k ) ( n k ) \displaystyle E(n) = 1 + p(n,0) \cdot E(n) + \sum_{k=1}^n p(n,k) \cdot (n-k) is a linear equation in E ( n ) E(n) , and by the fundamental theorem of algebra, it has exactly one solution.

Finally, we can check that E ( n ) = n E(n) = n is indeed a solution. The trick uses Lemma 1:

1 + ( k = 0 n p ( n , k ) E ( n k ) ) = 1 + ( k = 0 n p ( n , k ) ( n k ) ) = 1 + ( k = 0 n p ( n , k ) n ) ( k = 0 n p ( n , k ) k ) = 1 + n ( k = 0 n p ( n , k ) ) ( k = 0 n p ( n , k ) k ) = 1 + n 1 ( k = 0 n p ( n , k ) k ) = 1 + n 1 = n = E ( n ) \displaystyle\begin{aligned} 1 + \left( \sum_{k=0}^n p(n,k) \cdot E(n-k) \right) &= 1 + \left( \sum_{k=0}^n p(n,k) \cdot (n-k) \right) \\ &= 1 + \left( \sum_{k=0}^n p(n,k) \cdot n \right) - \left( \sum_{k=0}^n p(n,k) \cdot k \right) \\ &= 1 + n \cdot \left( \sum_{k=0}^n p(n,k) \right) - \left( \sum_{k=0}^n p(n,k) \cdot k \right) \\ &= 1 + n \cdot 1 - \left( \sum_{k=0}^n p(n,k) \cdot k \right) \\ &= 1 + n - 1 \\ &= n \\ &= E(n) \end{aligned}

The fourth line is because p ( n , k ) = 1 \sum p(n,k) = 1 . The fifth line comes from Lemma 1.

Since we know E ( n ) = n E(n) = n is a solution, and we know there is exactly only one solution, we can conclude that E ( n ) = n E(n) = n , completing the proof.

Now we just use the claim for n = 10 n = 10 , the given problem, to obtain E ( 10 ) = 10 E(10) = \boxed{10} attempts to get all couples right.


This problem (in a different wording, but essentially the same thing) is actually a problem in Google Code Jam, although I forgot which one.

Perfect, this is the intended solution. I actually had no idea it was from Google Code Jam, I was actually inspired by a show that my roommate watches, Are You The One, which has a similar concept. Thanks for posting the solution!

Garrett Clarke - 4 years, 10 months ago

Log in to reply

Magically, I managed to find the source: Google Code Jam 2011, Qualifying Round, Problem D: GoroSort . It is actually more complicated than that (the strategy is not spelled out like given here), but once you get that, the rest is identical.

Ivan Koswara - 4 years, 10 months ago

I'm curious: Do you have a Markov Chain solution?

Pi Han Goh - 4 years, 10 months ago

Log in to reply

I do, but Ivan's solution is much better than the way I originally solved it. I regret putting this problem in that chapter. I originally used Markov chains to solve this but it took way too long and I had to use excel to compute some values. This is when I realized that E ( n ) = n E(n)=n and figured out the other way to solve it, but when I posted the problem I just put it under Markov chains.

To solve it with Markov chains, assume that you have 10 states that you're working with: 0 couples found, 1 couple found, 2 couples found, ..., 7 couples found, 8 couples found and 10 couples found (if you've found 9, you must've found the last one as well). From there I manually computed the p ( n , k ) p(n,k) that Ivan spoke of above, put them in a transition matrix T T , found I T I-T , computed it's inverse with excel, then took the sum of the first row to get my answer, just to realize that the answer was an integer and that there was a much better way to solve it.

Like I said, his solution is MUCH better!

Edit: Didn't realize you could change the wiki: It's under Expected Value now.

Garrett Clarke - 4 years, 10 months ago

Log in to reply

@Garrett Clarke Good to know. Thanks for the wonderful question!

Pi Han Goh - 4 years, 10 months ago

Intuitively, the strategy of "Pick randomly each time" seems pretty weak. How much can a smarter picking strategy improve our guesses?

E.g. If at step n n , we pair husband k k with wife n + k n + k , then we need 9 tries to figure it out perfectly, and at the most using our 10th try to "confirm" the final pairing.

Calvin Lin Staff - 4 years, 10 months ago

I don't understand😭😭😭

Kimi Kimi - 4 years, 10 months ago

Log in to reply

Don't worry, neither do I. You will work your way up, if you desire to.

Alan Laifer - 2 years, 9 months ago
Abhishek Sinha
Oct 15, 2016

An elegant way to solve this problem is to use the theory of Martingales . Let C k C_k denote the number of correctly matched pairs after k k matching attempts. Define the random variables X k = C k k , k 0 X_k=C_k-k, k \geq 0 . Clearly, X 0 = 0 X_0=0 . We will show that { X k } k 0 \{X_k\}_{k\geq 0} constitutes a Martingale sequence, w.r.t. the filtration F n = σ ( C 1 , C 2 , , C n ) \mathcal{F}_n=\sigma(C_1,C_2,\ldots, C_n) .

For this, let us first compute expected number of new matches that we get after each matching attempt. Clearly, if there are m m unmatched pairs before the attempt, each of the pairs gets matched with probability 1 m \frac{1}{m} . Thus the expected number of new matches after the attempt, using the linearity of expectation, is 1 1 . Hence, E ( X n + 1 F n ) = E ( C n + 1 F n ) ( n + 1 ) = C n + 1 ( n + 1 ) = X n \mathbb{E}(X_{n+1}| \mathcal{F}_n)=\mathbb{E}(C_{n+1}|\mathcal{F}_n)- (n+1)= C_n+1-(n+1)= X_n Thus, it follows that { X k } k 1 \{X_k\}_{k \geq 1} is a Martingale sequence. Now define the stopping time τ \tau to be the first time for which C τ = 10 C_\tau=10 , i.e., all pairs are matched. Using the Optional Stopping Theorem , (using condition (b) for its validity) we get E X τ = E X 0 = 0 = E C τ E τ \mathbb{E}X_\tau= \mathbb{E}X_0=0= \mathbb{E}C_\tau-\mathbb{E}\tau i.e., E τ = 10 \mathbb{E}\tau=10 \hspace{10pt} \blacksquare

This is a very smart solution! Good job.

"Clearly, if there are m unmatched pairs before the attempt, each of the pairs gets matched with probability. Thus the expected number of new matches after the attempt, using the linearity of expectation, is 1."

This needs clarification as it may seem that you cannot write them as sum of expectations, as once a spot is taken others cannot take it. However, it turns out it does not affect the expected number of correct guesses.

Amir Yousefi - 2 years ago
Abhishek Kulkarni
Aug 11, 2016

After each try we get to know that if we have guessed correctly or wrong. So as there are 10 couples the number of tries will be 10

This is just a coincidence and is not a solution to the problem.

Garrett Clarke - 4 years, 10 months ago

Actually, I've just calculated E(n) for n (number of man and woman) = {1, 2, 3, 4} and the answers are respectively {1,2,3,4}.

There are n! different possible matches we can randomly guess.

E(1) = 1

E(2) = (1/2!) 1 + (1/2!) (E(2)+1) --> E(2) = 2

E(3) = (1/3!) 1 + (3/3!) (E(2)+1) + (2/3!)*(E(3)+1) --> E(3) = 3

E(4) = (1/4!) 1 + (6/4!) (E(2)+1) + (8/4!) (E(3)+1) + (9/4!) (E(4)+1) --> E(4) = 4

But I couldn't prove for n after that point. I would appreciate if someone could prove this sequence.

Arman Özcan - 1 year, 11 months ago
Vishal S
Sep 23, 2020

I just said 10 bc since there are 10 woman and men it must have taken 10 tries; there are a total 20 people and one couple is made out of 2 people so basically 20 divided by 2 :) Hope this helps

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...