Question
Consider the following Java code snippet: Â Â
import java.util.ArrayList;   import java.util.Arrays;   import java.util.List;   import java.util.PriorityQueue;   public class HeapQuestion10 {     public static void main(String[] args) {       List numbers = Arrays.asList(7, 2, 9, 1, 5);       PriorityQueue pq = new PriorityQueue(numbers); // Initialize with a collection       System.out.println(pq.poll());       System.out.println(pq.poll());       System.out.println(pq.poll());     }   }   What will be the output of this program?Solution
When a PriorityQueue is initialized with a Collection (like numbers list here), it performs a "heapify" operation. This operation builds a min-heap (by default) from the given elements. The time complexity for building a heap from N elements is O(N).   1. List
Which ministry hosted the 'Run for Sun' Marathon in New Delhi to celebrate International Sun Day?
Which institute recently signed an MoU with the Commissionerate of Indian Medicine and Homoeopathy (CIM&H) to carry out testing and standardization of s...
The Bumchu Festival is celebrated at which monastery?
With reference to salt caverns, consider the following statements:
1. They are used to store liquid fuels and natural gas in various parts of the...
According to the latest report of the Stockholm International Peace Research Institute (SIPRI) on Trends in International Arms Transfer 2021, India is _...
- What is the theme for World Art Day 2025 celebrated on April 15?
Which new system has the Indian Army launched to enhance generator tracking and protection?
First seminar of Agni Tattva Campaign under LiFE Mission was organized in _____.
Which company is planning to set up a Gorilla Glass manufacturing facility in Telangana with a proposed investment of Rs. 934 crore?
Recently NMCG and Sahakar Bharati organise the ‘Vishaal Kisan Sammelan’ in which of the following place?