← Heaps & Priority Queues Quiz: all 8 questions
Heaps & Priority Queues Quiz · Question 5 of 8
In Java, how do you create a max-heap of integers?
In Java, how do you create a max-heap of integers?
- A.new PriorityQueue<>()
- B.new PriorityQueue<>(Collections.reverseOrder())
- C.new MaxHeap<>()
- D.new TreeSet<>()
Answer & explanation
Correct answer: new PriorityQueue<>(Collections.reverseOrder())
PriorityQueue is a min-heap by default; reverseOrder() flips the comparison.
Can you get the rest right without peeking?
Take the timed Heaps & Priority Queues Quiz quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →