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 this​ video, Samir describes how business executives use a BI application to drill down and see​ _____ data, the detail in th
Zielflug [23.3K]

Answer and Explanation:

The answer is granular data.

Granular data is detailed data. As granular data is lowest level data, that can refer to the size as Granularity is the level of detail where data are stored in the database. For example, a table contains cost attributes but in both table cost to use for different columns and different purpose.

The other example of granular data is the name field is subdivided. Such as

First name, middle name, and last name.

Data becomes specific and conferred as more granular.

5 0
4 years ago
Please help me with this!
Aleksandr [31]

def zipZapZop():

   number = int(input("Enter the number: "))

   dictionary = {3: "zip", 5: "zap", 7: "zop"}

   amount = 0<em> #amount of non-divisible numbers by 3, 5 and 7</em>

<em>    for key, value in dictionary.items():</em>

       if(number%key == 0): <em>#key is the number</em>

           print(value) <em>#value can be or zip, or zap, or zop</em>

       else: amount += 1 #the number of "amount" increases every time, when the number is not divisible by 3, or 5, or 7

   if(amount == 3): print(number)    <em>#if the number is not by any of them, then we should print the number</em>

zipZapZop()

4 0
3 years ago
Correct or False, when formatting conditional data, I start by selecting the range of data that I want to format
Arturiano [62]

Answer:

Correct

Explanation:

4 0
3 years ago
who likes tom holland as spiderman and his web shooter tippets when he swings off buildings in new york city midtown, Forest Hil
S_A_V [24]

Answer:

YESSSS!!!!

Explanation:

5 0
3 years ago
Read 2 more answers
the server encountered an internal error or misconfiguration and was unable to complete your request.
mezya [45]
Error 404 - didn’t found
4 0
3 years ago
Other questions:
  • What is something you can do to stay connected to the relationships in your life while we spend this time at home?
    13·1 answer
  • How do you convert a binary number into a decimal number?
    6·1 answer
  • 16 to 19 year old drivers are how many more times likely to crash? 1.7,2.7,0.7 ,3.7
    12·2 answers
  • In an oblique drawing, which lines can be measured accurately, if there is no foreshortening?
    10·1 answer
  • 8.7 lesson practice question 1
    13·1 answer
  • A chain of coffee servers is sending a spreadsheet of projected costs and profits to some of its investors. When, Kyle, the admi
    7·1 answer
  • Help Me<br><br> What are the four types of graphic models?
    10·1 answer
  • If you need to modify a features in a part created using the Mirror tool, you can make the change in the original feature and th
    14·1 answer
  • Explain why this scenario could put an organization in jeopardy of losing some of its workforce.
    12·1 answer
  • How many 60 KB jpeg files can be stored on a 2 MB folder in your hard drive?​
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!