The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
0 votes

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.4k points) | 73 views

1 Answer

+2 votes
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 (4k points)

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

28,834 questions
36,688 answers
34,641 users