Every year, the government publishes a list of the top 10,000 baby names and their frequency (the number of babies with that name). The only issue is that some names have different spellings. For example, "John" and ".Jon" are the same name. However, they would be mentioned individually in the list. Write a method to produce a new list with the real frequency of each name given two lists, one of names/frequencies and the other of pairings of equivalent names. It is important to note that if John and Jon are synonyms, and Jon and Johnny are synonyms, then John and Johnny are synonyms. (It has both transitive and symmetric properties.) Any name on the final list can be used as the "actual" name. EXAMPLE Input: Names: John (15), Jon (12), Chris (13), Kris (4), Christopher (19) Synonyms: (Jon, John), (John, Johnny), (Chris, Kris), (Chris, Christopher) Output: John (27), Kris (36)
Every year, the government publishes a list of the top 10,000 baby names and their frequency (the number of babies with that name). The only issue is that some names have different spellings. For example, "John" and ".Jon" are the same name.
However, they would be mentioned individually in the list. Write a method to produce a new list with the real frequency of each name given two lists, one of names/frequencies and the other of pairings of equivalent names. It is important to note that if John and Jon are synonyms, and Jon and Johnny are synonyms, then John and Johnny are synonyms. (It has both transitive and symmetric properties.) Any name on the final list can be used as the "actual" name.
EXAMPLE
Input:
Names: John (15), Jon (12), Chris (13), Kris (4), Christopher (19)
Synonyms: (Jon, John), (John, Johnny), (Chris, Kris), (Chris, Christopher)
Output: John (27), Kris (36)
Step by step
Solved in 3 steps