1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
sashaice [31]
3 years ago
15

Describe an algorithm that, given n integers in range 0 to k, preprocesses its input and then answers any query about how many o

f the n integers fall into a range [a...b] in O(1) time. Your algorithm should use O(n+k) preprocessing time.
Computers and Technology
1 answer:
pogonyaev3 years ago
8 0

Answer:

Explanation:

Assume that our integers are stored in array A[1 · · · n] and thus, length[A] = n. We need two additional  arrays B[1 · · · k] and C[1 · · · k].

Our algorithm will first initialize all elements of array B to 0. This step

requires O(k) time.

Next, for each element of array A (i.e., A[i] for i = 1, 2, · · · , n), we will increment

B[A[i]]. Observe that this step will require O(n) time and B[j] for j = 1, 2, · · · , k, now contains the number

of elements of A having value j. Finally, make C[1] = B[1] and for each element l of array C where

l = 2, 3, · · · , k, we will compute C[l] = B[l] + B[l − 1]. This step takes O(k) time.

Now, to answer any query about how many of n integers fall into a range [a · · · b], we simply compute

C[b] − C[a] + B[a].

Observe that this computation requires only O(1) time after the O(n + k) preprocessing

time.

You might be interested in
In python how do you write for prime factors
olasank [31]

Answer:

The while loop is used and the factors of the integer are computed by using the modulus operator and checking if the remainder of the number divided by i is 0. 3. Then the factors of the integer are then again checked if the factor is prime or not.

Explanation:

google

4 0
3 years ago
How much water does the Hill family use per week?
Thepotemich [5.8K]

Answer:

The Hill family uses69 pints

Explanation:

bc why not

4 0
3 years ago
Which tools can be used to scale an object? Check all that apply.
meriva

Answer:

format picture pane

corner sizing handles

Explanation:

7 0
3 years ago
Thad found a website for his research about the U.S. Constitution. Which of the following is a clue that the source may not be r
vazorg [7]
<span>D. The information comes from the Library of Congress since its a official page </span>
8 0
3 years ago
Read 2 more answers
Where do you click to add keywords to describe your image?
Brut [27]

Answer:

D. I use a Mac and I right-click the file, then add tags. I can create new tags for describing a png image (or pdf if it was exported).

6 0
3 years ago
Other questions:
  • A(n ______ allows a user to specify a task without specifying how the task will be accomplished
    8·1 answer
  • While a hard drive is running, even a slight bump against the computer may cause the
    9·2 answers
  • Explain the purpose of the frame check sequence (fcs) field in a data link frame trailer.
    7·1 answer
  • The Internet may best be compared to a/an
    8·1 answer
  • You accidentally moved your task bar from the bottom of the screen to the left side. You would like to
    14·2 answers
  • Given two variables firstInClass and secondInClass which have already been associated with values, write code which swaps the va
    9·1 answer
  • Is monitor is a television​
    7·1 answer
  • Which of the following situations is least likely fair use
    6·2 answers
  • How does the variance as a measure of the dispersion of a data set relate to the measure of central tendency (i.e. mean)? What c
    14·1 answer
  • WILL GIVE BRAINLIEST IF DONE CORRECT
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!