answer.
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
Mandarinka [93]
2 years ago
13

Problem 2 - K-Best Values - 30 points Find the k-best (i.e. largest) values in a set of data. Assume you are given a sequence of

values, one value at a time. We do not know how many elements there are in this sequence. In fact, there could be infinitely many. Implement the class KBestCounter> implements KBest that keeps track of the k-largest elements seen so far in a sequence of data. The class should have two methods: public void count(T x) - process the next element in the set of data. This operation must run in at worst O(log k) time. public List kbest() - return a sorted (smallest to largest) list of the k-largest elements. This must run in at worst O(k log k) time. The method must not clobber the state of your class. This means that if you run this method twice in a row, it should return the same values. Your KBestCounter.java class must implement the provided interface KBest.java. Use a priority queue to implement this functionality. We suggest using the built-in java.util.PriorityQueue. As always, feel free to implement your own tester file to ensure proper functionality.
Computers and Technology
1 answer:
masya89 [10]2 years ago
5 0

Answer:

See explaination

Explanation:

/**KBestCounter.java**/

import java.util.ArrayList;

import java.util.List;

import java.util.PriorityQueue;

public class KBestCounter<T extends Comparable<? super T>>

{

PriorityQueue heap;

int k;

public KBestCounter(int k)

{

heap = new PriorityQueue < Integer > ();

this.k=k;

}

//Inserts an element into heap.

//also takes O(log k) worst time to insert an element

//into a heap of size k.

public void count(T x)

{

//Always the heap has not more than k elements

if(heap.size()<k)

{

heap.add(x);

}

//if already has k elements, then compare the new element

//with the minimum element. if the new element is greater than the

//Minimum element, remove the minimum element and insert the new element

//otherwise, don't insert the new element.

else if ( (x.compareTo((T) heap.peek()) > 0 ) && heap.size()==k)

{

heap.remove();

heap.add(x);

}

}

//Returns a list of the k largest elements( in descending order)

public List kbest()

{

List al = new ArrayList();

int heapSize=heap.size();

//runs O(k)

for(int i=0;i<heapSize;i++)

{

al.add(0,heap.poll());

}

//Restoring the the priority queue.

//runs in O(k log k) time

for(int j=0;j<al.size();j++) //repeats k times

{

heap.add(al.get(j)); //takes O(log k) in worst case

}

return al;

}

}

public class TestKBest

{

public static void main(String[] args)

{

int k = 5;

KBestCounter<Integer> counter = new KBestCounter<>(k);

System.out.println("Inserting 1,2,3.");

for(int i = 1; i<=3; i++)

counter.count(i);

System.out.println("5-best should be [3,2,1]: "+counter.kbest());

counter.count(2);

System.out.println("Inserting another 2.");

System.out.println("5-best should be [3,2,2,1]: "+counter.kbest());

System.out.println("Inserting 4..99.");

for (int i = 4; i < 100; i++)

counter.count(i);

System.out.println("5-best should be [99,98,97,96,95]: " + counter.kbest());

System.out.println("Inserting 100, 20, 101.");

counter.count(100);

counter.count(20);

counter.count(101);

System.out.println("5-best should be [101,100,99,98,97]: " + counter.kbest());

}

}

You might be interested in
Iris called the company’s security hotline. The hotline is an anonymous way to report suspi- cious activity or abuse of company
marishachu [46]

Answer 1 :

if Iris had approached Henry, it might had become a personal matter rather than professional. Following the proper protocol is the best way to report in any organization.

Answer 2 :

Yes, Gladys should call the legal authorities. Federal Trade Commission (FTC) is the best agency to file a complaint prevention of corruption within a company.

Answer 3 :

Yes, she should have followed her chain of command because that is one of the many questions that an investigator will ask is if she reported it to her supervisor and human resources. Somehow in companies they use that term when it is somewhat of a legal issue. Internally if she knew the IT director and the security office she could have gone to them along with human resources. Outside I would say start with her local police department and they may have directed her to the proper channel.

Answer 4 :

What Henry did was not ethical even in the slightest. He used the flash drive without permission from the company, he knew he shouldn’t have, but he did it anyway. It is acted in a complete ethical way. If Iris had left this in a coffee station and forgot about it, then it would have been unethical behavior because she knew about it but didn’t whistle blow. There are security laws that get violated in this issue which is why it is unethical and troublesome.

5 0
2 years ago
What is a text feature that could add visual interest and clarity to a procedural document?
rjkz [21]

Bullet points is another

3 0
2 years ago
Read 2 more answers
3. Personal Trainer is very concerned about the security and protection of the information they collect in the new information s
Sever21 [200]

Answer:

Check the explanation

Explanation:

in order to make sure that the built into the new systems, the below input and output levels of security control have to be considered for personal trainers staff.

There are:

   Network Security

   Application security

   Physical security

   User security

   File security

   Procedural security

These securities levels are consistent and advantage in building the decisions regarding system security.

There are the following policies applied to each control:

Network Security: Network interface and traffic controlling, encryption of data.

Application Security: Verification of data input/output and update of software proceedings.

Physical Security: Security to servers, computers and physical environment.

User Security: Protection passwords and identify management skills.

File Security: Access Permission allocated to users and editing authorizations given to users.

Procedural Security: Certify safety protection to perform decision-making activities and document shredders.

Finally, consider another main point is depends the new system performance are system response time, throughput, bandwidth time and turnaround time.

7 0
2 years ago
A wireless network does not benefit like a wired network does, when it comes to collision reduction. Which device reduces collis
Leviafan [203]

Answer:

Switch

Explanation:

The network switch is an networking hardware also known as a network bridging device used to connect devices on the network together and receives and forward data from source to destination through packet switching.

In order to eliminate or reduce collision within the network, present day wired networks make use of network switches that connects each device to its own port on the switch, making the switch the domain of collision for half duplex links or whereby the link is a full duplex links the collision possibility is completely eliminated.

3 0
2 years ago
Write a second convertToInches() with two double parameters, numFeet and numInches, that returns the total number of inches. Ex:
mixer [17]

Answer:

   public static double convertToInches(double numFeet, double numInches){

       return (numFeet*12)+numInches;

   }

Explanation:

This technique of having more than one method/function having the same name but with different parameter list is called method overloading. When the method is called, the compiler differentiates between them by the supplied parameters. The complete program is given below

public class FunctionOverloadToInches {

   public static void main(String[] args) {

       double totInches = 0.0;

       totInches = convertToInches(4.0, 6.0);

       System.out.println("4.0, 6.0 yields " + totInches);

       totInches = convertToInches(5.9);

       System.out.println("5.9 yields " + totInches);

       return;

   }

   public static double convertToInches(double numFeet)

       {

           return numFeet * 12.0;

       }

       /* Your solution goes here */

   public static double convertToInches(double numFeet, double numInches){

       return (numFeet*12)+numInches;

   }

}

5 0
2 years ago
Other questions:
  • Catherine wants to search online for fruit juices. She is fine with aerated or fresh fruit juices. Which Boolean operator will e
    12·2 answers
  • if you had two proxy servers located in the same room, what use could you make of them? nothing create a hub sell one of the ser
    14·2 answers
  • Matt is a senior developer for Cyber Protect, a company that helps secure management information systems. Matt's new task is to
    8·1 answer
  • A hotel salesperson enters sales in a text file. Each line contains the following, separated by semicolons: the name of the clie
    7·1 answer
  • Drag each tile to the correct box.
    8·2 answers
  • A chief Information Security Officer (CISO) is performing a BIA for the organization in case of a natural disaster. Which of the
    8·1 answer
  • Multiply each element in origList with the corresponding value in offsetAmount. Print each product followed by a semicolon (no s
    14·1 answer
  • Which of the following is true of how computers represent numbers?
    9·2 answers
  • Quantum units of information deploy the properties of entanglement and ____ to offer exponentially greater computing power.
    9·1 answer
  • There are some processes that need to be executed. Amount of a load that process causes on a server that runs it, is being repre
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!