All roads lead to Rome, some smooth, some rough.

Source: Internet
Author: User

 

AlgorithmIntroduction exercise 5.2.4 introduces a hat-Check Problem (hat-Check Problem): There are N Customers who give each of them a hat to the waiter who is responsible for keeping hats in the restaurant. The waiter returns the hats to the customer in random order. What is the expected number of customers who receive their hats?

Solution 1: Using the indicator random variables introduced in the introduction to algorithms, assuming that the random variable Xi satisfies (1 <= I <= N ):

 

 

Then the total random variable X meets the following requirements:

For each customer, the probability of getting his hat is 1/N, so:

So,

This idea is easy to think of Based on the explanation in the introduction to algorithms book, but when I really think about it, I can't help but go back to the inertial thinking of forgetting to learn probability theory, so I have knowledge of method 2, it is much more complicated than the solution.

Solution 2:

The basic idea is to use expectation = \ sum _ {I = 1} ^ {n} I * I to get my hat. In this way, we need to calculate the probability that only one person gets his hat. Easy to find, the key step is to find the probability that no one gets his hat, because there is a total number of cases where only one gets his hat by using C (I, n) the method of selecting will fix the person with the right hat, and then the remaining (n-I) people do not get the number of their hats for calculation. So I first converted the problem into the number of cases where n people did not get their hats. This problem is actually caused by the mistake of the envelope in the famous bonuli. You can solve the problem by using the refresh principle.

It is easy to get. The total number of hats I get is (n-1 )!, There are two people I and j take the right hat total number is (n-2 )!,..., There are (n-2) Individuals (people have been selected) Take the right hat Total number of cases is 2 !, There are (n-1) people with the right hats, that is, the number of N people with the right hats is 1. So the principle of rejection, the total number of people with the right hats is:

So the total number of hats that no one gets is:

In this way, the final answer is:

It can be proved that... (except for the mathematical induction, I have not come up with a better method.) The result of this summation is 1.

Both methods use algorithms in probability theory, starting with random variables and starting with expected definitions. Although the final results are obtained, solution 2 is obviously more complex.

I have never used mathematics for a long time, and my mind is very slow. Yesterday, I looked at Microsoft's notes and questions. Some of them looked like the questions of the same year's mathematical competition. They could be killed in a flash, but now they seem to have no idea for a long time. They have learned this for so many years, what have you learned ?... It is hoped that, along with the introduction to algorithms, you can find your own mathematical status.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.