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]
2 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]2 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
Ill give 100 points to whoever gives me the CORRECT answer. I keep getting syntax errors when I do the "add:" part. Can someone
Olin [163]

Answer:

sorry but there is not enough information to complete this

Explanation:

6 0
2 years ago
Read 2 more answers
You are the administrator for a network with a single Active Directory domain called westsim. All computer accounts reside in or
N76 [4]
Link a GPO to the Marketing OU. In the GPO, edit the Enable client-side targeting policy and specify the Marketing Computers group.

In the WSUS console, edit the options for Computers and specify Use Group Policy or registry settings on computers.

In the WSUS console, create a Marketing Computers group.
3 0
2 years ago
Does anyone know about the progressive era?
Umnica [9.8K]

Answer: The Progressive Era was a period of widespread social activism and political reform across the United States that spanned the 1890s to the 1920s.

Explanation:

8 0
3 years ago
Read 2 more answers
What is a music composition copyright?
Anestetic [448]
For copyright<span> purposes, there is a difference between </span>MUSICAL<span> COMPOSITIONS and SOUND RECORDINGS. A </span>Musical Composition<span> consists of </span>music<span>, including any accompanying words, and is normally registered as a work of performing arts. The author of a </span>musical composition<span> is generally the composer and the lyricist, if any.</span>
3 0
2 years ago
Read 2 more answers
What should you commit to your family members?
olganol [36]

Answer:

Find some time to do an activity that everyone in the family will love. Maybe share a movie night, trip to the park, or play your favorite game. Don't forget that old saying, “the family that plays together, stays together.” Doing fun things as a family can help to keep everyone's spirits up and strengthen ties.

Explanation:

HOPE IT'S HELP

PLEASE MARK AS BRAINLEST ANSWER

7 0
2 years ago
Other questions:
  • Students are studying the effects of beach pollution by counting populations of seagulls at two different beach locations. One l
    7·1 answer
  • With network management software, a network manager can ____.
    6·1 answer
  • Software (often on firmware) designed to make physical products and devices "smarter" by doing things like sharing usage informa
    12·1 answer
  • In a social networking site your personal information is listed under your?
    12·2 answers
  • When you move or size a control in the Form Designer, Visual Studio automatically adjusts the ________________ that specify the
    9·1 answer
  • Gathering information with your eyes is called
    13·2 answers
  • The software used to help run the computer hardware is the _____.
    15·2 answers
  • O O O O O O O
    9·1 answer
  • If a program compiles fine, but it produces an incorrect result, then the program suffers from _______________.
    11·1 answer
  • An operating system with _____ capabilities allows a user to run more than one program concurrently.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!