Data Structure and algorithm (Priority Queue/Heap) HELP inJava
Implement the following algorithm as a Java method.
We are interested in finding the kth largest element. Generate Nelements into an array.
At any point in time, we want to maintain a set ‘S’ of the klargest elements.
Create a heap from the first k elements in the array, ensuring thebuildHeap is used and not individual inserts.
For each remaining element in the array, if it is larger thanthe smallest value in the heap, remove the smallest and insert thenew value.
When all array elements have been processed, the smallest value inthe heap is the kth largest value
PayPal Gateway not configured
PayPal Gateway not configured