December 5, 2005
Consider the US government site www.ssa.gov/OACT/babynames that has data on the frequency of people's first names used in the United States.
For example, here are the top 10 names given to babies in 2004.
Lets consider that we use this site to collect the following data for girls' names. Each line represents the year and the top 1000 names in rank order (1st, 2cd, 3rd, etc...).
2004 | Emily | Emma | Madison | Olivia | Hannah | Abigail | ..... |
2003 | Emily | Emma | Madison | Hannah | Olivia | Abigail | ..... |
2002 | Emily | Madison | Hannah | Emma | Alexis | Ashley | ..... |
2001 | Emily | Madison | Hannah | Ashley | Alexis | Sarah | ..... |
2000 | Emily | Hannah | Madison | Ashley | Sarah | Alexis | ..... |
... | ... | ... | ... | ... | ... | ... | ... |
1960 | Mary | Susan | Linda | Karen | Donna | Lisa | ..... |
... | ... | ... | ... | ... | ... | ... | ... |
1920 | Mary | Dorothy | Helen | Margaret | Ruth | Mildred | ..... |
... | ... | ... | ... | ... | ... | ... | ... |
1880 | Mary | Anna | Emma | Elizabeth | Minnie | Margaret | ..... |
Assume this data is stored in two parallel arrays. The first array is called Dates and is an array of numbers with the years, and the second array is called AllNames and is an array of strings, each string is all the first names for a particular year, separated by blanks in rank order for that year. The kth position in Dates is the year for the names in the kth slot in AllNames. Assume slot 0 in dates is the year 1880, slot 1 is 1881, etc.
Write a function called AllMyRanks, that has three parameters: Name (a person's name), Dates, and AllNames.
This function should return an array of ranks for the given name. The first number (in slot 0) should be the rank of that person in 1880, the second number (in slot 1) should be the rank of that person in 1881. For example, if the name is Hannah, the numbers 2, 3, 3, 4, and 5 would be in the array in the slots associated with the years from 2000 to 2004.
You may use the following function in your code ( you do not have to write it). The function Rank has two parameters, name is a person's name and lotsOfNames is a string of names. Rank returns the rank of the person's name. For example, the call Rank("Madison", "Emily Hannah Madison Ashley Sarah Alexis ...") returns 3. Rank returns 0 if a name is not in lotsOfNames.
Write the function AllMyRanks below.
Write the function YearOfHighestRank that has three parameters: Name (a person's name), Dates, and AllNames. It should return the year in which this person had the highest rank. If a person's highest rank occurs in multiple years, you should return the most recent year.
For example, the call YearOfHighestRank("Emily", Dates, AllNames) returns 2004. Emily is first many years, the most recent year is 2004. Note 2004 is the last entry in Dates.
Write YearOfHighestRank below.
Sketch an outline of how you would determine the most popular name.