Question: (30 pts.) Given an array of n integers between 0 and m, you would like to find out how many of these numbers are between

 (30 pts.) Given an array of n integers between 0 and

(30 pts.) Given an array of n integers between 0 and m, you would like to find out how many of these numbers are between an arbitrary interval a and b in constant time. For example, given numbers 5,2,18,10,87,21,7,24, 9, you would like to compute how many numbers are between 10 and 20 in (1) time. It is straightforward to find the answer in O(n) time, but to be able to find the answer in constant time, you need to preprocess the array. Describe a (n + m) algorithm to solve this problem. You only need to write the pseudocode and do its complexity analysis. No implementation needed. Hint: Utilize the idea in counting sort to preprocess the array

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!