CS13002 PDS Lab, Spring 2003, Section 1/A

Supplementary Lab Test

[The birthday paradox]

Generate a random sequence of birthdays and store the birthdays in an array. As soon as a match is found, report that. Also report how many birthdays were generated to get the match.

Note:


Sample output

 1. March 12
 2. November 27
 3. May 27
 4. July 2
 5. April 18
 6. September 11
 7. February 13
 8. October 27
 9. September 15
10. January 11
11. October 29
12. December 23
13. January 5
14. February 1
15. June 13
16. December 28
17. November 12
18. October 15
19. July 4
20. January 21
21. February 24
22. July 29
23. January 17
24. April 6
25. March 26
26. November 1
27. January 5
Match found among 27 birthdays.
Birthdays no. 13 and 27 are the same...


Remark

It is surprising to see that you usually require a very small number of people (around 25) in order to have a match in their birthdays. However counter-intuitive it might sound, it is a mathematical truth, commonly known as the birthday paradox. In short it says that if you draw (with replacement) about sqrt(n) samples from a pool of n objects, there is about 50/50 chance that you get a repetition. If you draw 2sqrt(n) samples, you can be almost certain that there will be at least one repetition. In order to know more about the paradox and its mathematics, click here.


[Course home] [Home]