The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+16 votes
2.1k views

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

asked in DS by Veteran (59.4k points)
edited by | 2.1k views
0
I think its option A. What do u think>?
0
0
please explain sir. Also, why is it not option C ?
0
how option A
+1
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)  .

2 Answers

+28 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
answered by Boss (14.1k points)
edited by
0
frequency of each score above 50:

@bhagirathi mam

here frequency means continue incresing by 1? till 100

rght?
+3

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

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

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

0
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.
0
We can think it of hash table of 50 numbers
0 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();
     if(x>50)
   {
     P[x-50]++; // here we can use P[x] ++ but  for that we would require array of size 100
   }
}
}

Therefore answer is A
answered by Active (1.2k points)
edited by
Answer:

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

35,499 questions
42,765 answers
121,499 comments
42,151 users