Open In App

GATE | GATE-CS-2005 | Question 5

Like Article
Like
Save
Share
Report

A program P reads in 500 integers in the range [0..100] representing the scores of 500 students. It then prints the frequency of each score above 50. What would be the best way for P to store the frequencies?

(A)

An array of 50 numbers

(B)

An array of 100 numbers

(C)

An array of 500 numbers

(D)

A dynamically allocated array of 550 numbers



Answer: (A)

Explanation:

Explanation:

The program needs to store the frequency of each score above 50, which means it only needs to track the frequencies for scores ranging from 51 to 100. Since the scores are in the range [0..100], and the program is only interested in scores above 50, the possible scores to consider are from 51 to 100.

Given that the scores range from 51 to 100, there are 50 possible scores in this range. Therefore, using an array of 50 numbers is sufficient to store the frequencies for each score. Each element in the array can correspond to a specific score, where the index represents the score itself, and the value at that index represents the frequency.

For example, index 0 of the array can represent score 51, index 1 can represent score 52, and so on, up to index 49 representing score 100. By using an array of 50 numbers, the program can directly access the frequency for each score by its corresponding index.

Using an array of 50 numbers is a compact and efficient way to store the frequencies since it precisely matches the number of distinct scores above 50. It avoids unnecessary memory allocation and provides a direct mapping between scores and frequencies.

Therefore, the correct explanation is that option (A) An array of 50 numbers is the best way for the program P to store the frequencies of scores above 50.

See Question 1 of https://www.geeksforgeeks.org/data-structures-and-algorithms-set-22/

Quiz of this Question


Quiz of this Question
Please comment below if you find anything wrong in the above post


Last Updated : 28 Jun, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads