subject

Finding the k-largest values in a set of data - Assume you are given a sequence of values. We do not know how many elements there are in this sequence. In fact, there could be infinitely many. Implement the class KBestCounter> that keeps track of the k-largest elements seen so far in a set of data. The class should have two methods:
public void count(T x) - process the next element in the set of data. This operation should run in the at worst O(log k) time.
public List kbest() - return a sorted (largest to smallest) list of the k largest elements. This should run in O(k log k) time. The method should restore the priority queue to its original state after retrieving the klargest elements. If you run this method twice in a row, it should return the same values.
Use a Priority Queue to implement this functionality. We suggest using the built-in java. util. PriorityQueue, which implements a min-heap for you. You should never have more than k elements inserted into the Priority Queue at any given time.
import java. util. PriorityQueue;
public class KBestCounter> {
PriorityQueue heap;
int k;
public KBestCounter(int k) {
//todo
}
public void count(T x) {
//todo
}
public List kbest() {
//todo
}
}

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 03:30
Hashtags serve to identify the topic of a given tweet true false
Answers: 2
question
Computers and Technology, 23.06.2019 04:31
Acloud service provider uses the internet to deliver a computing environment for developing, running, and managing software applications. which cloud service model does the provider offer? a. iaas b. caas c. maas d. paas e. saas
Answers: 1
question
Computers and Technology, 23.06.2019 09:00
Before you record your own voice, you should a. record other people's voices b. warm up and practice difficult names c. listen to your favorite songs d. read a transcript of a good radio news segment
Answers: 1
question
Computers and Technology, 23.06.2019 12:00
If you embed a word table into powerpoint, what happens when you make edits to the embedded data? a. edits made to embedded data change the data in the source file; however, edits made to the source file will not be reflected in the embedded data. b. edits made to embedded data will change the data in the source file, and edits made to the source file will be reflected in the embedded data. c. edits made to embedded data don't change the data in the source file, nor will edits made to the source file be reflected in the embedded data. d. edits made to embedded data don't change the data in the source file; however, edits made to the source file will be reflected in the embedded data.
Answers: 1
You know the right answer?
Finding the k-largest values in a set of data - Assume you are given a sequence of values. We do not...
Questions
question
Mathematics, 26.02.2021 06:00
question
Mathematics, 26.02.2021 06:00