The Gateway to Computer Science Excellence
+24 votes

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?

  1. An array of $50$ numbers

  2. An array of $100$ numbers

  3. An array of $500$ numbers

  4. A dynamically allocated array of $550$ numbers

in DS by Veteran (52.2k points)
edited by | 4.2k views
I think its option A. What do u think>?
please explain sir. Also, why is it not option C ?
how option A
Here,  given prints the frequency of each score above 50 that means  500/ ( avobe 50) =  less than 10 score.

only 9 score which frelquency is avobe 50. we requare only an array of 9 number .

So by question best answer is (A)  .
we have to evaluate 500 records ranging between 0-100 but in the end we are interested in only marks greater than 50(printing frequency of each marks 51,52,...100) so only an array of size 50 will suffice...
Yes answer is option A ,

Just wanted to add a point :

Always think of worst case. coz one can argue that "I ll not give any student marks>=50" then no array will be needed but that couldn't be the case ''always".

So worst case would be -> allocate every student marks>=50 then max size of array neede is "50" because by pigeon hole principle , after 100 , elements will be repeated.


P.S :

Dont think like " I will give 51 marks to every student so that array of size only "1" will be sufficient.., bcause this is again not the worst case.
It's like counting sort in which there are 50 buckets (from 51 to 100) just read the marks of all students one by one and update the count in bucket of respective marks ..
it will be like an array A[50].

A[0] represents how many students got 51 marks("It then prints the frequency of each score above 50"), A[1] represents how many students got 52 marks(since 52>50) and so on.

2 Answers

+45 votes
Best answer
As we our area of interest is only the $50$ numbers so take An array of $50$ numbers where $A[0]$ corresponds to $51...A[49]$ corresponds to $100$ then after reading an input just increment the counter in correct position as said above.

Correct Answer: $A$
by Boss (14.4k points)
edited by
frequency of each score above 50:

@bhagirathi mam

here frequency means continue incresing by 1? till 100


 frequency : Number of times score is repeated i.e. 51 marks are getting by 10 students so the frequency of 51 is 10.

@bhagirathi why r u taking this "An array of 50 numbers where A[0] corresponds to 51...A[49] corresponds to 100 "?
@suvasish Because the problem statement asks for the frequency of student who scored more than 50 so why bother storing irrelevant data?

@ saxena0612 i understood that ,but A[0] can be 60 rather than 51?

Yes it can be! but iterating serially would be convenient rather than randomly .. Hope that make sense?
Like if you want to store the frequency of 60 in a[0] then presenting the complete chart of frequency would take a much longer than the stated way.
We can think it of hash table of 50 numbers
nice bhagirathi
It means if it found that 3 students got 51 marks then count is 3 and prints 3... And again it checks for 52... And if 2 students got 52 its count is 2....and again checks for 53.... 54.......... 100....

And in array of frequency

F[ 50] ={3,2,.....}

So absolutely the correct answer is "A" the array of 50 integers

Am I ryt?
count =100;

While (count)


 Accept score of student;

If (score > 50)





do we use counting sort or hash function??

+5 votes
Let read () be a function which returns the current value read from given  500 integers.

P[50] array of 50 elements ,where all elements is initialized to 0.

Program P()
For(i=1 to 500)
   x = read();
     P[x%50]++; // here we can use P[x] ++ but  for that we would require array of size 100

Therefore answer is A
by Active (2.4k points)
edited by

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,737 questions
57,385 answers
105,385 users