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
What is a small handheld computer that performs simple tasks such as taking notes, scheduling appointments, and maintaining an a
antiseptic1488 [7]

is a small handheld computer that performs simple tasks such as taking notes, scheduling appointments, and maintaining an address book and a calendar PDA.

<h3><u>Explanation:</u></h3>

Personal Digital Assistant is the full form for PDA. PDAs are the computers in smaller size. They perform all works that are performed by a computer. They help you in viewing all the documents that you need, scheduling all your works,etc. They act as a mini sized computer that you can take where ever you go.

Using PDAs you can easily schedule any tasks, take notes, maintain all your contacts in address books,etc. Even though the markets of PDAs is not having higher demands because of the existence of i phones and other devices that are identical to i phones, there are still some usages and demands for PDAs. These are used in industries and businesses.

3 0
3 years ago
Anyone got E-aqa login?​
pashok25 [27]

Answer:no

Explanation:

3 0
3 years ago
True / Fasle
Liono4ka [1.6K]

Answer:

False

Explanation:

3 0
3 years ago
Define the terms data and information ??​
lora16 [44]

Answer:

Data is an individual unit that contains raw materials which do not carry any specific meaning. Information is a group of data that collectively carries a logical meaning. Data doesn't depend on information. Information depends on data. It is measured in bits and bytes.

5 0
3 years ago
Read 2 more answers
What is a return statement used for?
Aleonysh [2.5K]

Answer:

Exiting a function

Explanation:

Return simply returns a specified value at the end of a def function (if you're in python). It does not print or do anything else. You could set variables equal to a def function that returns or you could put the def function in a print statement to print the returned value.

4 0
3 years ago
Other questions:
  • Most keyboards today are in a
    8·1 answer
  • A ____ is a theoretical model of computation that includes a (conceptual) tape extending infinitely in both directions.
    13·1 answer
  • ________ is a set of rules for exchanging files such as text, graphic images, sound, video, and other multimedia files on the we
    14·1 answer
  • When a rectangular region is defined using an appropriate style, which value matches the specified edge of the clipping region t
    7·1 answer
  • What formula would you enter to add the values in cells b4, b5, and b6?
    10·1 answer
  • What data unit is addressed based on the IP address of the recipient?
    8·1 answer
  • Creating a call conversion in Google Ads and adding a phone snippet to a web page allows advertisers to use a Google forwarding
    11·1 answer
  • The area of a square is stored in a double variable named area. write an expression whose value is length of the diagonal of the
    8·1 answer
  • Which role is delegated to personnel of the IT department and is responsible for maintaining the integrity and security of the d
    10·1 answer
  • If you were any type of fnaf charater who would you be and why?
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!