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 GND and what color wire do we connect to GND? (this is like for circuits and stuff btw)
fgiga [73]
Ground wire and i believe it is yellow and green
7 0
3 years ago
Which file extension takes less storage space?
anyanavicka [17]

I believe the answer would be the JPEG file extension.

4 0
3 years ago
Read 2 more answers
Chill and text part 2<br><br> (TEST) How do i copy apex questions
tresset_1 [31]

Answer:

Oracle doc...

7.3.4 Copying a Database Application Page

You can copy a page from the current application or from another application. During the copy process, you can also copy shared components or change mappings to shared components in the target application.

To copy a page:

Navigate to the application you want to copy to:

Navigate to the Workspace home page.

Click the Application Builder icon.

Select an application.

Select a page.

The Page Definition appears.

In Tree view:

Under Page Rendering, select the page name.

Right-click and select copy.

In Component view:

Under Page, click the Copy icon.

For Copy Page Option, select one of the following:

Page in this application

Page in another application

Follow the on-screen instructions.

8 0
3 years ago
Read 2 more answers
This exercise asks you to write a program that tests some of the built-in subroutines for working with Strings. The program shou
klasskru [66]

Answer:

Java.

Explanation:

// Get user input

System.out.print("Please enter your first name and last name separated by a space: ");

userInput = TextIO.getln();

// Find index of space character

int spaceIndex = userInput.indexOf(' ');

// Extract first and last name using space character index

// I have used length() method to get length of string userInput.

String firstName = userInput.substring(0, spaceIndex-1);

String lastName = userInput.substring(spaceIndex+1, userInput.length()-1);

// Print the required statements

System.out.print("Your first Name is %s, which has %d characters%n", firstName, firstName.length());

System.out.print("Your last Name is %s, which has %d characters%n", lastName, lastName.length());

// I have used space character Index to get the Initial of last name

System.out.print("Your initials are %s%s", firstName.substring(0,0), lastName.substring(spaceIndex+1, spaceIndex+1));

5 0
2 years ago
Which of the following statements best
antoniya [11.8K]

Answer

b

Explanation:

3 0
3 years ago
Other questions:
  • What are the cause of eye strain during computer usage?
    7·1 answer
  • Which reading strategy refers to reading only the key words and phrases?
    13·2 answers
  • Wich is the last step in conducting a URL search
    14·2 answers
  • Question 1 (1 point)
    10·2 answers
  • Write a MARIE program to allow the user to input 8 integers (positive, negative, or zero) and then find the smallest and the lar
    15·1 answer
  • An administrator has noticed that GPO containing new update settings has not yet applied to one of the computers on the network.
    5·1 answer
  • Which risk management framework does the organization of standardization publish
    13·1 answer
  • highlight the possible risks and problems that should be address during the implementation of information system process
    5·1 answer
  • WIRELESS DATA TRANSMISSION METHODS​
    8·1 answer
  • Choose the answer that best completes the visual analogy.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!