Introduction to algorithms 5.4 Further use of probability analysis and indicator random variables-interesting questions

Source: Internet
Author: User

1. birthday paradox

How many people must be in a room to make the chance of two people having the same birthday reach 50%?

1) Probability Analysis

Assume n = 365 days a year,

The probability that two people's birthdays fall on a fixed number of days R is 1/N * 1/n = 1/N ^ 2

The probability of two people's birthdays falling on the same day is N * 1/N ^ 2 = 1/n

Note that the probability of two people's birthdays falling on the same day = the probability of one person's birthdays falling on the specified day = 1/N depends on the coincidence that each person's birthdays are independent.

K people have at least two people with the same birthday probability equal to 1 minus the probability that all people have different birthdays. That is:

1-1 * (n-1)/n * (n-2)/n... * (n-k + 1)/n> = 1/2

=> (N-1)/n * (n-2)/n... * (n-k + 1)/n <= 1/2

By inequality: 1 + x <= e ^ x

=> E ^ {-1/n-2/n...-(k-1)/n} = e ^ {-K * (k-1)/2n} <= 1/2

=> K * (k-1)> = 2n * ln2

When K is 23, at least two people have the same birthday probability as 50% or more.

2) use random indicator variables to calculate the number of people expected to have at least two people with the same birthday.

Use X to represent the logarithm with the same birthday (one to two persons ),

In this case, a total of C (K, 2) people have the same birthday probability as 1/N.

So when there are K people, the expectation of the logarithm of the person with the same birthday is C (K, 2) * 1/N = K (k-1)/2N

K (k-1)/2n> = 1 to find K = 28 people, you can expect a person's birthday is the same.

Note 1) and 2) different descriptions are two different problems.

Certificate ---------------------------------------------------------------------------------------------------------------------------------------------------

2 balls and box (coupon collector issues)

If a person wants to collect each of B's different coupons, about B * LNB random Coupons will be required.

Use the ball and the box model to explain: Randomly place the same ball into B boxes.

1> how many requests fall into the specified box? Obey the two-state distribution (K; N, 1/B), the expected value is N/B.

2> how many balls do I need to play on average before at least one ball in a given box? Obey the geometric distribution. The probability is 1/B. The expected number before success is 1/(1/B) = B.

3> how many balls should I have before each box has at least one ball?

About B * LNB pitching can meet the conditions

See the document for proof

Certificate -------------------------------------------------------------------------------------------------------------------------------------------------

3 Series (expectation of continuous positive number of coins throwing n times)

The csdn algorithm version has the following discussion:

Professor Adrew recruited a graduate student and assigned him a task to take the coin for 100 times. If it was positive, he wrote 1 on the paper. If it was negative, he wrote 0 on the paper, finally, the sequence is sent to Professor Adrew. The student came back half an hour later and gave the following data. Professor Adrew immediately saw the data that the student was writing casually.
Can you guess why?

Data
1 0 1 0 0 1 0 1 0 1 0 1 1 0 1 0 0 1 0 1 0 0 1 1
1 0 0 1 0 0 1 0 0 1 0 1 0 1 1 0 1 0 1 0 1 1 1 1 0 1 0 0 1 0 1 0 1 1 1 0 1 1
0 0 1 1 0 1 0 0 1 0 1 0 1 1 0 1 0 1 0 0 1 0 0 1 1 0 1 0 1 0 0 1 1 0 1 1
1 0 1 1

Suppose you throw a coin n times. How long is the longest continuous positive sequence you expect? The answer is O (lgn)

See the document for proof

Certificate --------------------------------------------------------------------------------------------------------------------------------------------------

4. Online employment issues (Socrates's problem of picking wheat ears)

Modify the employment issue. Now we only hire once:

Select a positive integer k <n, and then reject the first K candidates before the interview. Then, hire the first candidate whose score is higher than that of all previous applicants, hire the last person.

ON-LINE-MAXIMUM(k, n)1 bestscore ← -∞2 for ito k3      do if score(i) > bestscore4            then bestscorescore(i)5 for ik + 1 to n6      do if score(i) > bestscore7            then return i8 return n

How can we find the desired maximum wheat spike?

The method is not to pick up the wheat ear in the first K times, but to find the maximum Wheat Ear and remember, in the next n-k wheat ears, the first wheat ears that were bigger than the largest of the first K were picked up, that is, the target wheat ears. If no one finds anything bigger than the first K, pick up the last n.

The key here is to get the value of K to make it more likely to pick up the largest wheat spike. According to the analysis of 67th and 68 pages of Introduction to algorithms (Chinese version), when this K value is N/e, then there can be at least 1/E of wheat ears with the highest probability channel. K = N/E

Certificate ---------------------------------------------------------------------------------------------------------------------------------------------------

Summary:

Learn about these issues. See the document for proof

The first five chapters are the first part of the introduction to algorithms-Basic Knowledge

Chapter 1 contains many interesting questions.

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.