Skip to content
Official PYQ · 2005

GATE CS 2005 Q5 — Arrays, Stacks and Queues

Explain with AI

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

Choose one option
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 [0,100][0, 100].
  • We only need to print the frequency of each score above 5050.
  • The scores strictly greater than 5050 are: {51,52,53,…,100}\{51, 52, 53, \dots, 100\}

The total number of distinct scores in this range is: 100−51+1=50100 - 51 + 1 = 50

We can map these 5050 possible scores to an array of size 5050 (with indices 00 to 4949), where index ii stores the frequency of the score 51+i51 + i. This provides O(1)O(1) direct access time and uses the minimum possible memory.

Therefore, an array of 5050 numbers is the best way to store the frequencies.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Arrays, Stacks and Queues questions