Discrete Math:
The Birthday Problem investigates the minimum number of people needed to have better than a 50% chance of at least two people have the same birthday. Calculating this probability shows that n = 23 yields a probability of approximately .506. Use the probabilistic algorithm called the Monte Carlo algorithm and find the number of people in a room that yields an approximate probability greater than .75.
Please use the following list to complete the problem
● Adopt the representation for a date as a number from 0 (for January 1st) to 364 (for December 31st). (You can use an alternate representation if you wish)
● Using a random number generator, create a birthday for everyone in the room and put these birthdays in a list.
● Check the list for two or more birthdays having the same date.
● Do this many times, say 1000 or 10000
● The number of times there is a match divided by the total is an approximation of the probability.
● As a check of your work, a room of 23 people with a 1000 trials should produce a probability of around .506. (give or take quite a bit). If the number of trials are increased to 10000, the probability settles down to .506 (with just a little give and take)
The code (the probabilistic algorithm called the Monte Carlo algorithm) is written according to the steps given in question.
The R code for generating 10,000 realizations of
birthdays and counting the number that has at least one birthday
matches is given below.
n <- 23
m <- 10000
CountB = array(dim =365)
p <- 0
for (j in 1:m){
B <- sample(0:364, size=n, replace=TRUE)
for (i in 1:365){
CountB [i] <- length(which(i-1 == B))
}
if (length(which(1 < CountB))>0)
{
p <- p + 1/m
}
}
p
As a check the output is which is very close to theoretical (given in question) 0.506.
Now we change the value of in the code and we see when , the number of people in a room that yields an approximate probability greater than 0.75 namely .
Get Answers For Free
Most questions answered within 1 hours.