TheDataGirl

A little blog about big data and other things

Birthday Problem

How many people do we need in a class to make the probability that two people have the same birthday more than ½?

We have n classmates

365 days in a year (ignoring leap years)

Duplicates(n) = 1 – No duplicates(n)

We need to find the value of n where Duplicates(n) > ½

For us to have no duplicates, each person must not share the same birthday. The first person has 365 possibilities, the second has 364 possibilities, the third 363 possibilities, etc

Thus, we need to figure out the value where,

Below we try some values,

Therefore, the answer is n = 23

To simulate this in R, we can use the following code,

birthday_problem <- function(number_of_students) {

     birthday <- 1:36

classmate_bdays <- sample(birthday,number_of_students, replace=TRUE)

                duplicates <- classmate_bdays[duplicated(classmate_bdays)]

                return (length(duplicates) != 0);

}

n<-23

rounds <-10000

results <- replicate (rounds, birthday_problem(n))

probability <- (length(which(results))/rounds)*100

probability

Leave a Reply

Your email address will not be published. Required fields are marked *