Answers for "extract max from max heap"

5

max heap java

import java.util.PriorityQueue;

public class MaxHeapWithPriorityQueue {

    public static void main(String args[]) {
        // create priority queue
        PriorityQueue<Integer> prq = new PriorityQueue<>(Comparator.reverseOrder());

        // insert values in the queue
        prq.add(6);
        prq.add(9);
        prq.add(5);
        prq.add(64);
        prq.add(6);

        //print values
        while (!prq.isEmpty()) {
            System.out.print(prq.poll()+" ");
        }
    }

}
Posted by: Guest on August-02-2020
0

minimum and maximum numbers of elements in a heap of height h

Hence the minimum number of nodes possible in a heap of height h is 2h.
Clearly a heap of height h, has the maximum number of elements when its lowest level is completely filled.
In this case the heap is a complete binary tree of height h and hence has 2h+1 -1 nodes.
Posted by: Guest on May-19-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language