Arrays & Linked Lists
![Question 5, GATE 2005: Read 500 integer scores in [0, 100] and print frequencies of scores above 50. Best frequency storage? A array of 50 numbers; B array of 100; C array of 500; D dynamically allocated array of 550.](../../assets/questions/CS-2005-Q5-1.webp)
Answer & solution
Answer: A (no official key was published)
Only scores 51 through 100 need counts, exactly 50 possible values. Maintain a 50-entry array initialized to zero and increment index score−51 whenever score>50. All 500 observations can be streamed without storage, so A.
The only reported scores are 51, 52,…, 100, exactly 50 possibilities. Allocate one counter for each and map a qualifying score s to index s−51. Increment its counter while reading; scores at most 50 need no stored frequency for the requested output. The program need not retain all 500 observations. This distinguishes number of possible output categories from number of input records.