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]
2 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:
pogonyaev2 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
Posts that you delete
kiruha [24]
Answer
are visible to others may already have been shared
8 0
2 years ago
Write a code segment that displays the values of the integers x, y, and z on a single line, such that each value is right-justif
Elena L [17]

Answer:

x = int(input ("enter first number: "))

y = int(input ("enter second number: "))

z = int(input ("enter third number: "))

print('%6d %6d %6d' %(x,y,z))

Explanation:

Using python programming language we receive three integers variables (x,y,z) then using string formatting (%6) which specifies that the output should be right justified with a width of 6, the values are printed out.

3 0
2 years ago
Create an java application that will process 3-digit numbers as follows:
alisha [4.7K]

Answer:

I dont not not the frsidjkbzxc.n bzl,b vbsv,gcjdvc,

Explanation:

5 0
2 years ago
Full form of http.<br>wrong answer will be reported ​
vodomira [7]

Answer:

So it is Hyper Text Transfer Protocol.

Hope it helps

6 0
2 years ago
Read 2 more answers
3. SmartArt can be used to create that highlight relationships between two items.
KengaRu [80]
<span>SmartArt can be used to create graphic organizers (Solution:B) that highlight relationships between two items. With SmartArt you can make visual representation of your ideas and information. The tool SmartArt is available </span>in Excel, PowerPoint, Word, but also you create SmartArt object in Outlook.
There are different layouts available for this type of representation.
8 0
3 years ago
Other questions:
  • Although the original BBS system was simple, it increased people's ability to communicate
    14·1 answer
  • Technology is often discovered by accident
    5·1 answer
  • When should you save your document?
    15·2 answers
  • What correctly describes the features of the service called kickstarter?
    14·2 answers
  • you are working on creating a business document with two other co-workers. Based on just information, which of the following pre
    14·1 answer
  • Create a Flowchart and write pseudocode for a program that allows the user to enter two integer values: a and b.
    8·1 answer
  • In this exercise, you are asking the user to set a alpha numeric password for any website. Put some conditions.
    8·1 answer
  • For all programs, you should write a small amount of code and _______
    6·1 answer
  • Which feature of REPL.it would you use to transmit your program to a friend?
    12·1 answer
  • WHAT ARE SOME PROS AND CONS OF HYDROGEN FUELL CELLS
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!