GATE / CS ARCHIVE

GATE CSE 2005 / QUESTION 5

Counting scores above fifty

Data Structures · Arrays & Linked Lists · Full GATE CSE 2005 paper

GATE 2005, Q5 1 mark · MCQ
Report issue

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.
Tap to enlarge
Your answer
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.

Original paper, page 1