edited by
20,558 views
46 votes
46 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

edited by

4 Answers

Best answer
74 votes
74 votes
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$
edited by
11 votes
11 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
edited by
3 votes
3 votes

Answer option (A) 

create an array of 50 elements where 0,1,2 index correspond to score 50,51,52 and so on  

see the below program 

0 votes
0 votes
Given that

Program P reads in 500 integers in the range [0,100] representing the scores of 500 students.

then prints the frequency of each score above 50.It means frequency of scores 51 to 100(because score range is given [0,100]).

Here to store frequency of scores 51 to 100 (50 scores) we can use array of size 50.

we can use array of size 50 with starting index 51 to last index 100 and we can store frequency of each score 51 to 100. Here in array 51 to 100 represents indexes and corresponding values represent frequency of each score.

[example: a[51...100]

a[51]=7(assume 51 frequency is 7)

a[52]=8(assume 52 frequency is 8)

….

…..

…..

a[100]=20(assume 100 frequency is 20)   ]

 

Correct Answer : A
Answer:

Related questions

22 votes
22 votes
3 answers
1
22 votes
22 votes
8 answers
2
Kathleen asked Sep 22, 2014
22,968 views
In a complete $k$-ary tree, every internal node has exactly $k$ children. The number of leaves in such a tree with $n$ internal node is:$nk$$(n-1)k + 1$$n(k-1) +1$$n(k-1)...
31 votes
31 votes
4 answers
3
Kathleen asked Sep 22, 2014
24,242 views
How many distinct binary search trees can be created out of $4$ distinct keys?$5$$14$$24$$42$
20 votes
20 votes
1 answer
4
Kathleen asked Sep 22, 2014
13,930 views
A priority queue is implemented as a Max-Heap. Initially, it has $5$ elements. The level-order traversal of the heap is: $10, 8, 5, 3, 2$. Two new elements $1$ and $7$ ar...