Question: JAVA Objective: Work with priority queues. Description: Solve the Selection Problem described in the chapter 6 slides using Algorithm 2 (slide 31). You may use

JAVA

Objective: Work with priority queues. Description: Solve the "Selection Problem" described in the chapter 6 slides using Algorithm 2 (slide 31). You may use the BinaryHeap class from the textbook: 
http://users.cis.fiu.edu/~weiss/dsaajava3/code/BinaryHeap.java
 Your program should take a command-line parameter for specifying which item to find, for example, 3 means find the 3rd largest. Name your class Selection. Include a main method which demonstrates that your algorithm works. 

JAVA Objective: Work with priority queues. Description: Solve the "Selection Problem" described

in the chapter 6 slides using Algorithm 2 (slide 31). You may

Selection Problem .Second Algorithm: to find kth largest element, the first k elements are placed into a heap by calling buildHeap in O(k) time. .Let Sk be the kth largest in the set. For each remaining element larger than Sk, remove Sk and insert the new element. When done, the k largest elements will be in the heap, with the kth largest at the root. buildHeap is O(k), each deleteMin and insert is O(log k). Result is O(k) + O( (N-k) log k)-O(N log k)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!