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
egoroff_w [7]
3 years ago
15

Design a data structure to support the following two operations for a set S of inte- gers, which allows duplicate values: • INSE

RT(S, x) inserts x into S. • DELETE-LARGER-HALF(S) deletes the largest d|S|/2e elements from S. Explain how to implement this data structure so that any sequence of m INSERT and DELETE-LARGER-HALF operations runs in amortized O(1) time per op- eration. Your implementation should also include a way to output the elements of S in O(|S|) time. Prove the running time of your implementation.
Computers and Technology
1 answer:
umka2103 [35]3 years ago
7 0

Answer and Explanation:

Note that we are free to use any data structure that allows for arbitrary insertion and deletion of data

As an underlying data structure, we’ll use an (unsorted) array. INSERT(S, x) will  simply append x to the array, increasing its length. This has a constant runtime,  so we’ll say its cost is 1.

DELETE-LARGER-HALF(S) will work as follows: first, use SELECT to find the  median. Next, use PARTITION around the median to make sure that the upper half is stored within the last [|S|/2] elements. Finally, we delete these elements,  reducing the size of the array.This has a linear running time, so we’ll say its cost is n.

To show that any m operations can run in O(m) time, we define a potential  function \phi(S) = 2|S|. The amortized cost of INSERT is thus 1 + \delta \phi = 1 + 1 = 1 ;  the amortized cost of DELETE-LARGER-HALF is n +\delta\phi\leq n-2(n/2) = 0. So the  amortized cost of any m operations is O(m).

This answer essentially captures the idea behind the problem. However, there  are some technical points to clear up. (Calling the real-time costs 1 and n are not among them; this underestimates the running time by at most a constant. Ignoring constants like that is necessary to make concise arguments about amortized costs.)

First, an array does not support arbitrary insertions. Possible remedies include:

(1) using a dynamic array along the lines of §17.4, or (2) using a different structure  like a linked list, and having DELETE-LARGER-HALF convert it to an array and  back in linear time so that the SELECT and PARTITION algorithms may be used.

Second, it’s important to know which median to partition around and how to  delete the upper half of the elements: a mistake could lead to incorrect behavior when the array has an odd size or repeated elements. We should select the lower median,[|S|/2], since that’s the number of elements we want in the lower set: as  written, the CLRS Partition function will put elements less than or equal to the

pivot in the left set, and strictly larger elements in the right set. (If the partition function is defined differently, the answer should be different as well. You generally  should give a brief description of how your partition function works.) After a call to Partition, it is safe simply to keep the first [|S|/2] elements and drop the rest. On the other hand, it is not safe to go around deleting every element with

a sufficiently large value—take an array of zeros as a drastic example. If you wish  to take that approach, you’ll have to count the number of elements equal to the  median and delete the correct number of them.

Finally, the argument only shows that the <em>amortized</em> cost with respect to \phi is  O(m). The conclusion we’re asked for requires a technical condition: the potential  \phi never drops below its initial value. This is true for the usual reason: initially,  \phi = 0 because S is empty; during execution, \phi \geq 0  by definition.

You might be interested in
What websites can help you learn about general career treads
Tcecarenko [31]
Hi!

The Bureau of Labour Statistics is a government site which is specifically made just for this purpose.

By using it, you have access to thousands of jobs with tons of great factual information. 

Hopefully, this helps! =)
6 0
3 years ago
In an ha configuration, which two failure detection methods rely on icmp ping? (choose two.)
Hunter-Best [27]
I believe that the multiple questions attached to this question is 

a) Hello
b) Link groups
c) Path groups
d) Heartbeats

The Answer is B and C
The physical interfaces that are supposed to be monitored are connected into a link group and a firewall failure can be triggered when one or all physical interfaces in the group failPath Monitoring helps monitor the full path to mission critical IP addresses. By default, any one of the IP addresses becoming unreachable will end up causing the firewall to change the HA to tentative state
7 0
2 years ago
What are the ASE special certifications?
kykrilka [37]

Answer:

It is The National Institute for Automotive Service Excellence.

Explanation:

8 0
3 years ago
Read 2 more answers
The IT department sent out a memo stating that it will start delivering desktop computer interfaces through the IT data center v
Tasya [4]

Answer: Virtual desktop infrastructure

Explanation:

The virtual desktop infrastructure is the virtualization technology in which the host desktop OS (operating system)  is in the centralized server of the data center. The virtual desktop infrastructure is also known as server based computing as it include the variation in the computing model such as client - server model.

The example of the virtual desktop infrastructure is wallpapers, toolbars, window and folder is the stored in the server remotely.

All the other options does not involve with this technology so that is why option (D) is correct.

4 0
3 years ago
Which processor interrupts the system 18.2 times per second? What are some of its practical uses?
julsineya [31]

Answer:

timer interrupt

Explanation:

A timer is an interrupt that is generated by the PC's system timer.When this interrupt occurs, the ROM BIOS interrupt handler is called and it increments a count in the ROM BIOS.It interrupts the system 18.2 times per second.It is used for multitasking.Hence we conclude that timer interrupt is the answer.

6 0
3 years ago
Other questions:
  • If a user receives a message whose tone and terminology seems intended to invoke a panic or sense of urgency, it may be a(n) ___
    13·1 answer
  • From the standpoint of the governing bodies of .com, why is it important that owners of individual domains maintain authoritativ
    5·1 answer
  • In order to do a binary search on an array Group of answer choices you must first do a sequential search to be sure the element
    5·1 answer
  • Whats the size of a short bond paper in microsoft word?
    10·1 answer
  • If you filmed a clip in 120fps, how many frames are in a seconds of video.
    13·1 answer
  • Which CSS attribute would change an element's font color to blue
    15·2 answers
  • Write a program that has the user input how many classes they are taking this semester and then output how many hours they will
    8·2 answers
  • Can a dod activity enter into a service contract for a military flight simulator without getting a waiver from the secretary of
    13·1 answer
  • The use of technology to observe a user's actions often without the user's knowledge is known as:
    11·1 answer
  • If you want to join all of the rows in the first table of a SELECT statement with just the matched rows in a second table, you u
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!