A program reads in integers in the range representing the scores of students. It then prints the frequency of each score above . What would be the best way for to store the frequencies?
View worked solution
Answer: A
To find the most efficient way to store the frequencies, we analyze the range of scores we need to track:
- The input scores are integers in the range .
- We only need to print the frequency of each score above .
- The scores strictly greater than are:
The total number of distinct scores in this range is:
We can map these possible scores to an array of size (with indices to ), where index stores the frequency of the score . This provides direct access time and uses the minimum possible memory.
Therefore, an array of numbers is the best way to store the frequencies.
Free practice · Your answers on this page are not saved.
