GATE CSE
First time here? Checkout the FAQ!
x
0 votes
30 views

A program P reads the 500 numbers in the range [1, 2, …., 100] to represent the ranks of 500 students. If the program P prints the frequency of each rank above 50, then 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.   An array of 550 numbers
asked in DS by Active (1.3k points)   | 30 views

1 Answer

+1 vote
Answer should be A.

We have to store frequencies. In the range [1,2, ... , 100] there are 50 numbers which are greater than 50. To store the frequency we can create an integer array, say freq, of 50 elements and then value of

freq[0] denotes the frequency of rank 51,

freq[1] denotes the frequency of rank 52, and so on and finally,

freq[49] denotes the frequency of rank 100

So at the minimum, we need array of 50 elements.
answered by Loyal (3k points)  

Related questions

0 votes
0 answers
1
asked in DS by srestha Veteran (49.7k points)   | 35 views
+1 vote
0 answers
3
asked in DS by Akriti sood Veteran (10.2k points)   | 27 views
Top Users Jan 2017
  1. Debashish Deka

    8280 Points

  2. sudsho

    5042 Points

  3. Habibkhan

    4716 Points

  4. Vijay Thakur

    4468 Points

  5. Bikram

    4368 Points

  6. saurabh rai

    4212 Points

  7. Arjun

    4052 Points

  8. santhoshdevulapally

    3732 Points

  9. GateSet

    3312 Points

  10. Sushant Gokhale

    3306 Points

Monthly Topper: Rs. 500 gift card

19,138 questions
24,046 answers
52,772 comments
20,283 users