Summary of the most frequently investigated probability questions in Internet company interviews

Regardless of applying for data analysts, algorithms, or other data-related positions, famous companies often have probability interview questions.

The reason is that probability-based interview questions can comprehensively test the interviewer's thinking ability, adaptability, and mathematical ability.

If you don't prepare, impromptu thinking will be particularly time-consuming and labor-intensive. Here I have collected and summarized probabilistic questions with my friends from the fan group, hoping to help everyone.

Technology Exchange

Technology must learn to share and communicate, and it is not recommended to work behind closed doors. A person can go fast, a group of people can go farther.

This article is shared and organized by fans of the technology group. The source code, data, and technical exchanges of the article can be obtained by adding the exchange group. The group has more than 2,000 members. The best way to add notes is: source + interest direction, which is convenient for finding like-minded friends.

Method ①, Add WeChat ID: pythoner666, Remarks: from CSDN + Remarks
Method ②, WeChat search official account: Python learning and data mining, background reply: add group

Question 1

Question: What is the probability that a wooden stick, cut in three, will form a triangle?

answer:

Let the first paragraph cut off x, the second paragraph cut off y, and the third paragraph 1-xy.
Consider all possible intercepts. In the possible interception method, it is necessary to ensure that the three sides are all positive numbers and less than the original side length, then there are 0<x<1, 0<y<1, 0<1-xy<1, and we can see from the drawing that (x,y) must be in The half right triangle in the lower left corner of the unit square has an area of ​​1/2.

Then consider the cuts that can form a triangle. First of all, the three conditions 0<x<1, 0<y<1, 0<1-xy<1 must be met, and then the requirements of the sides of the triangle must be met, that is, the sum of the two sides is greater than the third side, x+y> 1-xy, x+1-xy>y, y+1-xy>x, simplification is
0<x<1/2, 0<y<1/2, 1/2<x+y<1

It can be seen from the drawing that at this time (x, y) must be in the half right triangle at the upper right corner of the triangle whose side length is 1/2, and the area is 1/8.

The final probability is then (1/8)/(1/2) = 1/4.

Question 2

Question: Toss a six-sided dice, toss continuously until it reaches 6, and ask what is the expected number of tosses.

answer:

Because the probability of throwing 6 is equal to 1/6 each time, the expected number of times is 1/(1/6)=6 times.

Let's use a different method to answer, assuming that the expected number of times is E. Consider the first throw, if you have already thrown 6 (probability 1/6), then you don't need to throw it again. If you don't get a 6 (probability is 5/6), then you need to continue tossing, but how many times do you have to toss?

Obviously, now I know that the number of throws to 6 is still E, but I have just thrown it once, so I can get this equation
E = 1 * 1/6 + (1 + E) * 5/6,

Solving for E = 6. That is, the expected number of times is 6 times.

Question 3

Question: There are M white balls in a wooden bucket. A ball is randomly taken out of the bucket every minute and painted red (whether it is white or red) and then put back. What is the expected time to paint all the balls in the bucket red?

answer:

Let there be i red balls in the bucket and then the expected time to paint all the balls red is a[i]. The expected time of is still a[i]. If it is white (probability 1-i/M), put it back after painting red, and the remaining expected time is a[i+1],

则 a[i] = (1 + a[i]) * i/M + (1 + a[i+1]) * (1 – i/M)

即   a[i] = a[i+1] + M/(M-i)

Clearly, there is a[M] = 0

It can be solved that a[0] = M/M + M/(M-1) + ... + M/1 + 0

Question 4

Question: You have a sword. For each gem used, there is a 50% chance of successfully leveling up the sword, and a 50% chance of failure. If the level of the sword is greater than or equal to 5, then failure will reduce the level of the sword by 1. If the level of the sword is less than 5, failure has no effect. The question is: How many gems are expected to take a level 1 sword to level 9?

answer:

The problem is relatively simple, use a[i] to represent the number of gems expected to be used to upgrade from level i-1 to level i.

When i<=5, because there will be no degradation, the expected number is 2, that is, a[2] = a[3] = a[4] = a[5] = 2

When i>5, because it will be downgraded, one gem is enough if successful, and you need to go back one level when unsuccessful, you need to use a[i-1] gems to return to level i-1 first, and then use a[i ] Gems are promoted to the i-th level, that is,
a[i] = 1 * 1/2 + (1 + a[i-1] + a[i]) * 1/2

immediately a[i] = a[i-1] + 2

Known, a[6] = 4, a[7] = 6, a[8] = 8, a[9] = 10

Then the number of gems required from level 1 to level 9 is a[2]+...+a[9] = 36.

Question 5

Question: It is known that there is a rand7() function, which returns a random natural number from 1 to 7. How to use this rand7() to construct rand10(), which can randomly 1~10.

answer:

The main principle of generating random numbers is that the probability of occurrence of each number is equal. If a group of numbers with equal probability can be obtained, then a method of mapping 1 to 10 can be found from it.

rand7() returns a natural number from 1 to 7, construct a new function (rand7()-1)*7 + rand7(), this function will randomly generate a natural number from 1 to 49. The reason is that each number in 1 49 is only represented by the value of the first rand7() and the value of the second rand7(), so the probability of their occurrence is equal.

But there are too many numbers here, you can discard the numbers 41 49, divide the numbers 1 40 into 10 groups, and map each group to one of 1~10, so you can get random results.

The specific method is to use (rand7()-1)*7 + rand7() to generate a random number x, if it is greater than 40, continue random until it is less than or equal to 40, if it is less than or equal to 40, the generated random number is (x-1 )/4+1.

Question 6

Question: Give a method to randomly select m numbers from n numbers. n is very large, which can be considered to be at the level of 100 million. m can be very small, such as close to 1; it can also be very large, such as close to n.

answer:

A direct idea is to repeat the random process until m numbers are randomized. This method has two disadvantages:
1. It is difficult to know whether a number randomly obtained later has been randomized before, because the amount of data is too large to be stored in memory, and it will take too much time to save it to external memory.

2. If m is very large, even close to n, then the numbers randomly obtained later are basically randomized before, so too many random times need to be tried.
One way of thinking is that the probability of each number being selected is m/n, then you can traverse the original data once, and decide whether to select the current number with the probability of m/n while traversing each number, then when the traversal is complete, select The number obtained is m in the average sense. This will better approach m as n increases, but it cannot accurately guarantee that the number of random numbers must be m.

Although the above ideas cannot meet the requirements, we can make improvements. When we traversed each number just now, we decided whether to choose the number with the same probability m/n. In fact, we already know the result of the previous number before the currently traversed number. We can randomly As a result, the current random strategy is dynamically adjusted, so that it can finally ensure that the number of random numbers must be m.

The specific method is that when traversing the first number, there is a probability of m/n to select. If the first number is selected, the probability of the second number being selected is adjusted to (m-1)/(n-1) , if the first number is not selected, the probability of the second number being selected is m/(n-1). That is, when traversing to the i-th number, if k has been selected at this time, then decide whether to select the current i-th number with the probability of (mk)/(n-i+1).

In this way, it can be guaranteed that an appropriate number can be selected from the remaining numbers every time so that the total number of selected numbers is m. For example, if m numbers have been randomized before, the probability of subsequent randomness becomes 0. If no number has been randomized before, the probability of being randomized later will be close to 1. The final result is always exactly m numbers.

Question 7

Problem: Give a method to randomly select 1 from n numbers. Note that n is very large, and its exact value is not known initially. The numbers are given to you one by one, and you must immediately give a random result after the numbers are given.

answer:

The value of n here is very large, and the answer is required to be given immediately, so it is not possible to save all the numbers first, and then slowly consider which one to randomize.

This question is similar to the above question, because we don't know how many numbers there are, so we must have a current result when we get each number, so that we can give the answer when the number is given.

So the first number must be taken. The question is when the second number comes, should I keep the number in hand or take the current second number? More generally, when the i-th (i>1) number comes, should you keep the number in hand, or choose the current i-th number?

The answer is to ensure that the probability of each number being selected is equal. When the i-th number comes, if we have ensured that the probability of each number being selected for the first i-1 numbers is equal, then as long as the i-th number The probability that a number is selected is 1/i, we can know that the probability of all i numbers being selected is 1/i. So you only need to decide whether to select the current i-th number with a probability of 1/i.

So it can be guaranteed that for any n, when n numbers are given, the probability of selecting each number is equal, which is 1/n.

Question 8

Question: Give a method to randomly select m numbers from n numbers. Note that n is very large, and its exact value is not known initially. The numbers are given to you one by one, and you must immediately give a random result after the numbers are given.

answer:

This question is an extension of the previous question, so it can be followed.
First of all, the first m numbers must be taken. The question is when the i (i>m) number comes, should we discard this number or keep it? If you want to keep this number, you have to discard the m numbers already in your hand, so how do you determine which one to discard?

The following is the specific approach. When the i-th number comes, decide whether to choose this number with the probability of m/i. If this number is chosen, one of the m numbers in hand is randomly replaced.

If the first i-1 numbers ensure that the probability of each number being selected is equal, then after doing so, the probability of each number being selected can be guaranteed to be equal, which is m/i.
1. The probability of selecting the i-th number is m/i, because this is how the algorithm decides.

2. Consider any one of the first i-1 numbers, the probability that it is selected before the i-th number is m/(i-1). When the i-th number is selected, there are two possibilities for this number to be selected. One is that the i-th number is not selected (probability is 1-m/i), and the other is that the i-th number is selected (probability is m/i) but the replaced number is not it (the probability is 1-1/m), so the probability that this number is still selected at the i number is m/(i-1) * ((1-m/ i) + (m/i * (1-1/m))) = m / (i-1) * ((i-1) / i) = m/i.

According to the principle of mathematical induction, for any n, when n numbers are given, the result of the selection can ensure that the probability of each of the n numbers being selected is equal

Question 9

Question: There are 100 white balls and 100 black balls in a bucket. Now take the balls according to the following rules:
- i. Take out two balls from the bucket each time;
- ii. If you take out two balls of the same color, then Put in another black ball;
- iii. If two different colored balls are taken out, put in another white ball.
Question: What is the probability that there is only one black ball left in the bucket at the end?

answer:

Dynamic programming, let f[i,j] represent the probability that there are i white balls and j black balls.
Given that f[100,100] = 1, find f[0,1].
Get two white balls: f[i-2,j+1] = i/(i+j) * (i-1)/(i+j-1) * f[i,j] get two black
balls Ball: f[i, j-1] = j/(i+j) * (j-1)/(i+j-1) * f[i,j] gets one black and one white: f[i
, j-1] =2 * i/(i+j) * j/(i+j-1) * f[i,j]

Question 10

Question: 10 people go out to play, the gathering time is 10 minutes, everyone arrives within this time, the probability is evenly distributed, independent of each other, then what is the most likely time for the last person to arrive?

answer:

When you encounter this kind of incomprehension, the best way is to enumerate.
If the last person arrives at 10 minutes (probability 1/10), everyone else has also arrived (probability 1), the total probability is 19 * (1/10)
if the last person arrives at 9 minutes (probability 1/10) 10), the probability of others arriving is (9/10)9, the total probability is (9/10)9 * (1/10)
and so on. It can be seen that the highest probability is the 10th minute.

Question 11

Problem: 100 people line up, everyone can only see the color of the hat of the person before him (assuming only black and white), everyone has to guess the color of his hat, he can only say once, if he says wrong, he will die, others You can hear the answers of the previous people and whether they died. May I ask what strategy to use to say that the least number of people die.

answer:

Assuming there are only 3 people, assuming ture = white, false = black, using this formula x3 = (x1 == x2), in human terms, if the hats of 1 and 2 are the same color, they will be white, and if they are different, they will be black. The probability of the first person dying in this strategy is 1/2, and the remaining two will not die.

Extended to 4 people, that is, x4 = (x3 == (x1 == x2)), it can be extended to 100 people. But the problem is that it is difficult for people to judge, and it can only be calculated by a computer.
Another way to solve the problem: "The last person checks whether the number of black hats in front is odd or even. For example, it is agreed that odd numbers are black, and even numbers are white. In this way, the people in front can infer the correct result."

Question 12

Question: 54 cards are divided into three piles on average. What is the probability that the big and small kings are in the same pile?

answer:

Divide into three piles on average, the probability that the king is in the first pile is 1/3, and the probability that the king is in the same pile as the king is 17/53 among the remaining 53 cards. By analogy, the king may also be in the 2,3 pile, so
1/3∗17/53∗3=17/53

Question 13

Question: When buying beverages, three bottle caps can be exchanged for one bottle. If you want to buy 100 bottles of beverages, how many bottles do you need to buy at least?

answer:

Suppose you want to buy x bottles.
x+x/3>=100
right? careful! x/3 bottles can be exchanged if there are 3 full bottles. Imagine someone frantically opening bottles at the entrance of the canteen. So it should be
x+x/3+x/9+...+x/3n>=100
n=log3x
x(1−1/3n)/(1−1/3)>=100
x(1−1/x )>=200/3
x=68

But I went back to do the math, and found that x=68 can only buy 99 bottles... After all, x is a real number when doing the calculation, so it is more reliable to go back and push, x=69.

Question 14

Question: There is a very large input stream, which is so large that there is no memory to store it, and it is only input once. How to randomly obtain m records from this input stream with medium probability.

answer:

If you can enter twice, then you can count the total number N, and then randomly count from 0 to N-1, and make a heavy judgment. But you can only enter it once here, and here are two methods.

The first. During the input process, a random number of [0,1] is given to each record, and finally the first m records with the largest random number are taken. It can be maintained with a small root pile of m size.

The second type is reservoir sampling or reservoir sample. Assuming that the nth record is entered, the number is taken with the probability of m/n. If it is selected, one of the m records originally taken will be randomly replaced. Initially, the first m records are selected. At first glance, it seems unreliable, but once it is proved, it will be convinced. The proof is also simple.
Assuming that it is true when n-1 is established, that is, the first n-1 records are all judged with the probability of m/(n-1) whether they are selected or not. We want to prove that after inputting the nth record, the first n records are all selected with the probability of m/n.

For the nth record, select it with the probability of m/n, ok, meet the requirements. Now look at the remaining top n-1 records. For the i-th record selected in the first n-1 records, it is currently possible to be selected, or the n-th record is not selected (1-m/n) * (m/(n-1)), Either the nth record is selected but i is not replaced by m/n * (m-1)/m * m/(n-1), the sum of the two is exactly equal to m/n, which is so cool.

In addition, there is an extended version, which is selected with different weights, refer to this article

Question 15

Question: On a highway, the probability of seeing a car in 30 minutes is 0.95, what is the probability of seeing a car in 10 minutes? (assuming the probability of passing a car is constant)

answer:

Note that the probability of seeing a car within 10 minutes is p. Then the probability of not seeing a car in 30 minutes is (1−p)3=1−0.95=0.05

So p=1−0.051/3

Question 16

Question: You and your friends go to a party, and there are 10 people including you and your friends. Your friend bets you that you get $1 for finding someone with the same birthday as you, and $2 for anyone he finds with a different birthday. Would you take this bet?

answer:

The description of the topic is a bit subtle. Let’s understand it here. If you find one with the same birthday, you will get $1, if you find two, $2, and so on. He gets $2 for finding one with a birthday different from yours, and $2 for as many people as he finds.
Assuming that there are 365 days in a year, everyone was born in the same year (same age). His expectation of getting money is 2∗(1−(1/365)10). The probability of you getting $1 is C1101/365(364/365)9, and the probability of getting $2 is C210(1/365)2 (364/365)7...This is a binomial distribution. The expectation is np=10∗1/365=10/365. It seems that the other party's number is bigger, so you can't bet.

Question 17

Question: There is a triangle with three ants on the three endpoints. The ants can go around any side. What is the probability that the ants will not collide? At first glance, it is a bit
confusing...

answer:

It's actually very simple...
1. There are only 2 possibilities for each ant to choose the direction. There are 3 ants in total, so there are 2 to the
power of 3 possibilities. Clockwise or all counterclockwise.

Probability of non-collision = non-collision / all = 2/8

Question 18

Question: Mr. and Mrs. Smith's Handshake Problem

The Smiths invited four other couples to dinner, each of whom was known not to shake hands with themselves, with their spouses, or with the same person more than once. After everyone met and shook hands, Smith asked everyone how many times they shook hands, and everyone answered differently. Q: How many times does Mrs. Smith shake hands?

Answer:
1. A total of 10 people, each person does not shake hands with himself, his spouse, or with the same person more than once, so each person shakes hands at most 8 times, and at least 0 times; 2. Mr.Smith asked other
9 Individuals shake hands several times, and each answer is different, so the number of handshakes for each person is exactly 0-8 times, and there is 1 person for each different number of times; 3. There is and only one person
shakes hands 8 times, which is called A, that is, everyone except A and his spouse shook hands;
4. Record A’s spouse as a, except for the A couple, everyone shook hands (and A) at least once, so the person who shook hands 0 times must be a;
5. Remove couple A from the 10 people, because A shook hands with everyone else once, but a did not shake hands with others, so after removing couple A, the number of handshakes of other people is 1-7 (excluding Mr. .Smith), and then remove the handshake they each held with A, so the number of handshakes for each person is 0-6, or there is exactly one person for each different number of times; 6. Repeat steps 3-5
4 times, until 4 couples are removed, and finally Mr. & Mrs.Smith is left. At this time, the number of handshakes of Mrs.Smith is 0, plus the 4 handshakes removed in the 4 cycles, she shook hands ¬4 times in total, and One person from each couple shook hands once.

A couple, invite N-1 couples to the party. Between husband and wife, the husband must know his wife. Everyone shakes hands once with someone they don't know. When the handshake was over, the host came forward and asked everyone else about the handshake. It was found that any one person's handshake situation is different from others. Ask you, how many times did the hostess shake hands (the answer is N-1 times)

Question 19

Question: A businessman in city A has a donkey and 3000 carrots. If he wants to sell the carrots to city B 1000 kilometers away, he can only use the donkey to carry them. It is known that a donkey can carry 1000 carrots at a time, but it needs to eat one carrot for every kilometer it travels. How many carrots can the merchant sell in total?

answer:

The problem with this question is that the conditions given are not sufficient. There may be two situations. One is the non-ideal state of hauling radishes. In this case, none of them can be sold; the second is the ideal state. It can be unloaded every kilometer, and there are no other external factors that make the radishes lose. Under such an ideal state, 833 radishes can be transported to City B.

The calculation process is as follows: 1. Since there are 3000 radishes, when the previous 1000 radishes are consumed, 3 radishes need to go back and forth 3 times for every kilometer forward, so the first time you have advanced X kilometers, X=1000/3= The remainder of 333 is 1; 2. The remaining 2001 radishes need to go back and forth 3 times to be transported at the 334th kilometer. We will count this kilometer as the 2000 radishes when they are transported for the first time. Then the second radish delivery only needs to consume 2 radishes back and forth twice, so the second time consumes 1000 radishes to advance Y kilometers, Y=1000/2=500; now it has advanced 500+333=833 kilometers, leaving 167 After one kilometer, there are only 1,000 radishes left, so these 1,000 radishes arrive at City B once without unloading, consuming 167 radishes, so 1000-167=833 radishes are left in the end.

Question 20

Problem: Eight Queens Problem

Algorithm introduction The eight queens problem is a problem in the background of chess: how to place eight queens on an 8×8 chessboard so that no queen can directly capture other queens? To achieve this, no two queens can be on the same horizontal, vertical or diagonal line.

answer:

The eight queens problem can be extended to a more general n queens placement problem: at this time the size of the chessboard becomes n×n, and the number of queens also becomes n. The problem has a solution if and only if n = 1 or n ≥ 4.

Question 21

Problem: In a jury of three, the probability that two of them make the correct decision is P. The other person always decides who to support by tossing a coin. In the end, the result is determined by a majority vote. The other trial is decided by a person whose probability of making the correct decision is also P. Who has a greater probability of making the right decision, a three-person jury or a one-person trial?

answer:

are equally large, with probability p

Because for a three-person jury, the correct probability is
p*(1-p)*0.5+p*(1-p)*0.5+p*p*0.5+p*p*0.5=p

Question 22

Question: There is an apple, and two people toss a coin to decide who will eat the apple, and the person who flips heads first will eat. What is the probability of getting an apple by tossing it first?

answer:

At first glance, the answer to this kind of question seems to be 1/2, but in fact, it is not that simple to think about it carefully.

Number all coin toss operations starting from 1. Obviously, the first mover can only get apples in odd (1,3,5,7…) coin tosses, and the second hand can only get apples in even (2,4,6,8…) times. ) toss a coin to get an apple. Let p be the probability that the first player gets an apple, the probability of getting an apple in the first coin toss is 1/2, and the probability of getting an apple after the third (3,5,7...) is p/4 (this is because This is only possible when neither the first nor the second coin toss turns heads (probability 1/4=1/2*1/2), and at this time the first mover faces the same situation). So the equation p=1/2+p/4, p=2/3 can be listed.

Now the answer is very clear, so everyone should be careful not to be deceived like this, and of course not to deceive others, haha~

Question 23

Question: A line segment of length l, randomly select 2 points on it, divide the line segment into 3 segments, what is the probability that these 3 sub-segments can form a triangle?

answer:

Let the two randomly selected numbers be x, y, and let y>x, then the length of the three segments cut from the line segment with a length of 1 is x, yx, 1-y, according to the sum of the two sides of the triangle is greater than the third side and the two sides The difference is less than the theorem of the third side, you can list the equation system
y>1-y; x<1-x; x+(1-y)>yx;
that is, x<1/2; y>1/2; y> x+1/2;

Drawing a picture can be calculated as a probability of 1/8;

Question 24

Question: You have two jars and 50 red marbles and 50 blue marbles. Randomly select a jar and randomly select a marble from it. How do you give the red marble the greatest chance of being selected? In your In the plan, what is the probability of getting a red ball

answer:

The title means that there are 50 red and 50 blue pinballs in the two jars, and then I choose a jar, and the maximum probability of selecting a red ball from it is to design a plan for how to put the 100 balls in the two jars. One jar: 1 red ball Another jar: 49 red balls, 50 basketball chances=1/2+(49/99)*(1/2)=74.7%

Question 25

Question: A deck of 54 cards is now divided into 3 equal parts with 18 cards each. What is the probability that the big and small kings appear in the same part?

Answer 1:

The 54 cards are divided into 3 equal parts, and there are M=(C54 takes 18)*(C36 takes 18)*(C18 takes 18) division methods.

Among them, there are N=(C3 takes 1)*(C52 takes 16)*(C36 takes 18)*(C18 takes 18) ways to divide the big and small kings in the same share.

Therefore the probability sought is P=N/M=17/53.

Answer 2:

You may wish to record three copies as A, B, and C. One of the big and small kings must be in a certain share, assuming that it is in share A, the probability is 1/3. Then A has only 17 cards that may contain another king, while B and C each have 18 cards that may contain another king, so the probability that A contains another king is 17/(17 +18+18)=17/53.

Therefore, it can be seen that the probability that part A contains both big and small kings is 1/3 * 17/53.

The question asks about the probability of appearing in the same copy, so the requested probability is 3*(1/3 * 17/53)=17/53.

Question 26

Question: Suppose you're on a game show and you have to choose one of three sealed boxes. Two of the boxes are empty, and the other box contains the grand prize (your idol's autograph ^^). You don't know which box the prize is in, but the host does. The game show host first asks you to choose a box, then he opens the empty box you didn't pick to prove it's empty. In the end, the host will give you the chance to change the box. You can change the box you choose to another box that has not been opened. Should you switch boxes at this point?

analyze:

Trust your instincts. Of course you should change the case! Let's number the three boxes A, B, and C, and assume you picked box A. Obviously the probability of the prize being in A is 1/3, and the probability of being in B or C is 2/3. One of B and C may be empty, or both may be empty. So when you select box A, the moderator will most likely open box B or C to show that it is empty. In this case, the host's actions do not affect the chances of the prize being in Box A. Let's assume the moderator opened box B to tell you it was empty. Now the probability that there is a prize in box A is still 1/3, the probability that there is a prize in box B is 0, so the probability that there is a prize in box C is 2/3. In this case, you should switch to Box C, as it doubles your chances of winning!

Question 27

Question: There is an apple, and two people toss a coin to decide who will eat the apple, and the person who flips heads first will eat. What is the probability that the first tosser gets the apple?

analyze:

The first thing I thought of was the probability of the first toss to the front + the probability of the second toss + ... + infinite times, of course, the probability of the latter is almost 0. The result is P = 1/2 + 1/8 + 1/32+ ... The final result is P = 2/3. This calculation is not difficult, in fact, it is a geometric sequence, the ratio is 1/4. Simple infinite level Number (1/2) / (1-1/4) = 2/3. 1/(1-x) 2 =1+2x+3x 2+4x 3+5x 4+… (-1<x<1)

There is another analysis by someone else: number all coin toss operations starting from 1. Obviously, the first player can only get apples in odd (1, 3, 5, 7...) coin tosses, while the second hand can only get apples in even (2 ,4,6,8...) Toss a coin to get an apple. Let p be the probability that the first player gets an apple, the probability of getting an apple in the first coin toss is 1/2, and the probability of getting an apple after the third (3,5,7...) is p/4 (this is because This is only possible when neither the first nor the second coin toss turns heads (probability 1/4=1/2*1/2), and at this time the first mover faces the same situation). So the equation p=1/2+p/4, p=2/3 can be listed.

Question 28

Question: A couple has two children, one of which is a girl, what is the probability that the other is a boy?

answer:

The answer is 2/3. The gender of the two children has the following four possibilities: (male) (male) (female) (female), one of them is a girl, and (male) is excluded, leaving three Condition. The other is that boys accounted for two types, 2/3. The reason why the answer is not 1/2 is because it is uncertain whether the girl was born first or second.

Question 29

Problem: A country where people only want boys and every family will keep having children until they get a boy. If it was a girl, they would have another one. If a boy is born, there will be no more. So, what is the ratio of men to women in this country?

answer:

At first, I took it for granted that there are more men than women, because after all, they all want boys. But pay attention to the saying "if a boy is born, there will be no more", a family may have multiple girls and only one boy. After careful analysis, let's calculate the expected value, and only need to calculate one family. Suppose the expected value of the number of boys in a family is S1, and the number of girls is S2.

According to the conditions of the question, the expected value of the number of boys S1=1 does not need to be calculated. Main calculation S2

The number of children in a family can be: 1, 2, 3, 4, 5... The corresponding distribution of men and women is: "male", "female man", "female man", "female man", "female Female Female Female Male”…

The corresponding probability distributions are 1/2, 1/4, 1/8, 1/16, 1/32. The numbers of girls are 0, 1, 2, 3, 4...

So S2=0*1/2 + 1*1/4 + 2*1/8 + 3*1/16 + 4*1/32 + ………

You can use series according to question 2, or you can use dislocation subtraction method: S2=1/4+2/8+3/16+4/32+... Multiply both sides by 2, get: 2*S2=1/2+ 2/4+3/8+4/16+5/32+…

Subtract the two formulas to get S2=1/2+1/4+1/8+1/16+1/32+…=1. So the expected value is 1, and the ratio of male to female is the same.

Question 30

Question: 10 people go out to play, the gathering time is 10 minutes, everyone arrives within this time, the probability is evenly distributed, independent of each other, then what is the most likely time for the last person to arrive?

Answer:
When you encounter this kind of incomprehension, the best way is to enumerate.
If the last person arrives at 10 minutes (probability 1/10), everyone else has also arrived (probability 1), the total probability is 19 * (1/10)
if the last person arrives at 9 minutes (probability 1/10) 10), the probability of others arriving is (9/10)9, the total probability is (9/10)9 * (1/10)
and so on. It can be seen that the highest probability is the 10th minute.

Question 31

Question: You and your friends go to a party, and there are 10 people including you and your friends. Your friend bets you that you get $1 for finding someone with the same birthday as you, and $2 for anyone he finds with a different birthday. Would you take this bet?

Answer:
The description of the title is a bit subtle. Let’s understand it here. If you find one with the same birthday, you will get $1, if you find two, you will get $2, and so on. He gets $2 for finding one with a birthday different from yours, and $2 for as many people as he finds.

Assuming that there are 365 days in a year, everyone was born in the same year (same age). His expectation of getting money is 2∗(1−(1/365)10) . The probability of you getting $1 is C1101/365(364/365)9, and the probability of getting $2 is C210(1/365)2 (364/365)7 ...This is a binomial distribution, and the expectation is np=10∗1/365=10/365. It seems that the opponent's number is bigger, so you can't bet.

Question 32

Question: It is known that there is a rand7() function that returns a random natural number from 1 to 7. Let this rand7() be used to construct rand10() to randomly 1~10.

answer:

The method used is similar to the previous question, how can an independent event of equal probability be obtained. The difference between this question and the previous question is that if the sequence generated here is to be in the form of sum or other forms, then the probability will change.

If you can get a set of numbers with equal probability, no matter what the number is, as long as the probability is equal and the number is greater than 10, then the problem can be solved.

It is found that (rand7()-1)*7+rand7() can generate 1 to 49 with equal probability.

Hehe, this is not enough, just cut off 11-49. However, this efficiency is relatively low. You can cut off 41-49, and then map 1-40 to 1-10, then the problem will be solved.

Guess you like

Origin blog.csdn.net/qq_34160248/article/details/130174921