Question
Consider the following Java code snippet: Â Â
import java.util.PriorityQueue; Â Â public class HeapQuestion1 { Â Â Â Â public static void main(String[] args) { Â Â Â Â Â Â PriorityQueue minHeap = new PriorityQueue(); Â Â Â Â Â Â minHeap.add(10); Â Â Â Â Â Â minHeap.add(5); Â Â Â Â Â Â minHeap.add(20); Â Â Â Â Â Â minHeap.add(3); Â Â Â Â Â Â minHeap.add(15); Â Â Â Â Â Â System.out.println(minHeap.poll()); Â Â Â Â Â Â System.out.println(minHeap.peek()); Â Â Â Â Â Â System.out.println(minHeap.poll()); Â Â Â Â } Â Â } Â Â What will be the output of this program?Solution
A PriorityQueue in Java is by default a min-heap, meaning the smallest element has the highest priority.   1. minHeap.add(10); minHeap.add(5); minHeap.add(20); minHeap.add(3); minHeap.add(15);     After these additions, the heap contains {3, 5, 10, 15, 20} (not necessarily in this order internally, but 3 is at the root).   2. System.out.println(minHeap.poll());     poll() removes and returns the smallest element. So, 3 is removed and printed. The heap now contains {5, 10, 15, 20}.   3. System.out.println(minHeap.peek());     peek() retrieves the smallest element *without removing it*. The smallest element is now 5. So, 5 is printed. The heap still contains {5, 10, 15, 20}.   4. System.out.println(minHeap.poll());     poll() removes and returns the smallest element again. So, 5 is removed and printed. The heap now contains {10, 15, 20}.   Therefore, the output is 3, 5, 5.
Which is relational Database
The error in Simpson's 1/3 Rule is proportional to:
Abstraction in OOP primarily focuses on:
Which algorithm divides the input array into two halves, sorts each half, and then merges the sorted halves?
What is a "collision" in the context of hashing?
Deadlock can arise if four necessary conditions hold simultaneously. Which of the following is NOT one of them?
The precision is composed of which of the following two characteristics?
What is "serverless computing"?
___________________ is the amount of time taken to fulfill the request by the process. It can be calculated by taking the difference between the complet...
What is capacity of memory having 16 address lines of row decoder, 8 address lines for column decoder and 8 data lines?Â