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
The Domain Name Service is what translates human-readable domain names into IP addresses that computers and routers understandA.
Mars2501 [29]

Answer:

True

Explanation:

A Domain Name Service comprises of computer servers that carries a database of public IP addresses and their related human-readable domain names/hostnames, it receives query as hostnames and helps to translates those human-readable domain names/hostnames into IP addresses that computers and routers understand.

5 0
3 years ago
Under what driving conditions will 2019 Nissan LEAF’s available Rear Cross Traffic Alert (RCTA) warn the driver if a vehicle is
Dmitriy789 [7]

Answer:

When the driver is <em>reversing the car</em>

Explanation:

The Rear Cross Traffic Alert (RCTA) is Nissan's <em>risk  of collision detector</em> that warns drivers if one or more cars are approaching the rear of your car when backing up from a parking space.  

Sensors around the back of the vehicle identify vehicles drawing nearer from the either way. A notice tone and glimmering light will appear and  alert the driver to stop.  

5 0
3 years ago
How to show neither precious nor accurate
ella [17]
When it is shining it is precious. When it is normal it is accurate.











Please make as brainliest please please
8 0
3 years ago
What did you predict will happen? Check all that apply. The lioness will attack Thisbe. Thisbe will stay hidden in the cave to a
sesenic [268]

Hi,


Everything applies. It is impossible to predict based on the current data. All scenarios are possible with equal possibility.


Hope this helps.

r3t40

5 0
3 years ago
Read 2 more answers
1. What is scratch programming?<br><br>2. What is a sprite?
JulsSmile [24]
1. The answer to the question what is scratch programming is a language and an online community where children can program and share interactive media

2. The answer to the question what is a sprite is a two dimensional bitmap that is intergrated into a larger scence.

Hope this helps
If you don't understand plz message me
If you do plz brainlest me
If you need help with any other tecnology questions you can also message me for that too.
Thank you and have a wonderful day!!!
3 0
3 years ago
Other questions:
  • Ultimately, there exists a ceiling on efficiency because _______________.
    10·1 answer
  • A restaurant chain has several store locations in a city (with a name and zip code stored for each), and each is managed by one
    9·1 answer
  • After placing her insertion point after Grandma’s Kitchen, order the steps Danica needs to follow to insert and format the regis
    8·2 answers
  • What happens if i receive a text while my phone is off?
    15·1 answer
  • In cell h15 enter a vlookup function to determine the 2018 percentage of total attendance for the city listed in cell h14. Use t
    7·1 answer
  • Egyptian hieroglyphs were part of a writing system used by the ancient Egyptians. What type of graphic design elements did they
    13·1 answer
  • How much days are in a year
    9·2 answers
  • ____ is the security guarantee that people who intercept messages cannot read them. A. Availability B. Encryption C. Confidentia
    9·1 answer
  • With which type of social engineering attack are users asked to respond to an email or are directed to a website where they are
    9·1 answer
  • Block elements start a new line when rendering? (true or false)
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!