Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The Birthday Problem The Birthday Problem is: if there are a group of n people i

ID: 2991685 • Letter: T

Question

The Birthday Problem The Birthday Problem is: if there are a group of n people in a room, what is the probability that two or more of them have the same birthday? It is possible to determine the answer to this question by simulation. Write a Junction that calculates the probability that two or more of n people will have the same birthday, where n is a calling argument. (Hint: To do this, the function should create an array of size n and generate n birthdays in the range I to 365 randomly. It should then check to see if any of the n birthdays are identical. The function should perform tins experiment at least 5000 times, and calculate the fraction of those times in which two or more people had the same birthday.) Write a test program that calculates and prints out the probability that 2 or more of n people will have the same birthday for n = 2,3, ... , 40.

Explanation / Answer

Since I don't know matlab, I will attempt to explain what you need to do. You will need to start with a loop that goes 5000 times and will contain the meat of your program. Inside, you can generate random numbers from 1-365 to fill an array which holds the birthdays of the people. Then, you could have a loop that goes 1-365 and counts the number of occurrences of the particular day with another loop. If the occurences are > 1, then that time, two or more people had the same birthday, so it can advance a counter. At the end of all this, just put the counter over n and print!