subject
Computers and Technology, 04.03.2020 23:37 Hfruit

A median priority queue. Given a set of keys, a median key is a key in the "middle" when the keys are sorted. When the number of keys is odd, the middle key is unique. However, when the number of keys is even, there are two middle keys. We call on the lower median key and the other the upper median key. For example, if the keys are {3, 8, 2, 10,5,9), then the lower median key is 5 while the upper median key is 8.
For this problem, we wish to implement the MedianPQADT that supports the following methods in O(logn) time:
Insert Item(k, e), RemoveLower Median(), Remove UpperMedian().
When n is even, the items to return for RemoveLowerMedian() and RemoveUpper Me dian() are obvious. When n is odd, let these methods simply return the item with the median key.
Our implementation involves two heaps -a max-heap H, and a min-heap Hr. It always maintains the property that contains the [n/2 smallest keys and HR contains the [n/2] largest keys.
(a1) Assume your current set of items are stored using the two-heap im- plementation with the said property. Write a pseudocode for the three methods Insertitem(k, e), RemoveLowerMedian(), Remove Upper Median().
(a2) Briefly argue why the running times of your pseudocodes for the three methods is O(logn).
(b) Starting with an empty two-heap, do six Insertitem with keys 6, 5, 4, 3, 2, 1. Draw what the heaps look like at the end of each insertion step. Then apply RemoveLower Median() and draw the tree at the end of this step.

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 18:30
Write a program that prints the day number of the year, given the date in the form month-day-year. for example, if the input is 1-1-2006, the day number is 1; if the input is 12-25-2006, the day number is 359. the program should check for a leap year. a year is a leap year if it is divisible by 4, but not divisible by 100. for example, 1992 and 2008 are divisible by 4, but not by 100. a year that is divisible by 100 is a leap year if it is also divisible by 400. for example, 1600 and 2000 are divisible by 400. however, 1800 is not a leap year because 1800 is not divisible by 400.
Answers: 3
question
Computers and Technology, 23.06.2019 20:30
What are some settings you can control when formatting columns?
Answers: 1
question
Computers and Technology, 24.06.2019 05:30
Someone plzz me which of these defines a social search? a. asking a search engine a question that is answered by a real person on the other sideb. modifying search results based on popularity of a web pagec.modifying search results based on a ranking of a web page
Answers: 2
question
Computers and Technology, 24.06.2019 16:00
Read these lines from beowulf.often scyld scefing seized mead-benches from enemytroops, from many a clan, he terrified warriors, even thoughfirst he was found a waif, best explains why the author includes this information in theexposition? a. to emphasize that a hero must learn to be fierceb. to remember the famous story of a popular heroc. to express sadness about losing the old heroesd. to see whether people still respect the old heroes
Answers: 1
You know the right answer?
A median priority queue. Given a set of keys, a median key is a key in the "middle" when the keys ar...
Questions
question
Mathematics, 18.04.2020 21:22
question
Mathematics, 18.04.2020 21:22
question
Mathematics, 18.04.2020 21:22
question
Social Studies, 18.04.2020 21:22
question
Social Studies, 18.04.2020 21:22
question
Mathematics, 18.04.2020 21:22
Questions on the website: 13722361