Question
What is the typical time complexity for removing the
highest-priority element (using poll()) from a java.util.PriorityQueue with N elements?   import java.util.PriorityQueue;   public class HeapQuestion4 {     public static void main(String[] args) {       PriorityQueue pq = new PriorityQueue();       pq.add(10); pq.add(5); pq.add(20); // Assume pq contains N elements       pq.poll(); // What is the time complexity of this operation?     }   }Solution
When the highest-priority element (root) is removed from a binary heap (poll() or remove()), the last element in the heap is moved to the root's position. To restore the heap property, this new root element then "bubbles down" (or "heapifies down") by repeatedly swapping with its smallest (or largest, for max-heap) child until its correct position is found. Similar to insertion, this process involves traversing a path from the root to a leaf, which is proportional to the height of the heap. Since the height is O(log N), the time complexity for removal is O(log N).
A and B entered into a business investing their capital in the ratio of 16:21, respectively and the respective ratio of time for which they made their i...
Ravi and Mohan started a business by investing Rs. ‘X’ and Rs. (X + 600), respectively. 18 months later, Mohan withdrew his entire investment. At th...
- Aman and Rohit invested Rs. 1500 and Rs. 2000 in a venture. After 8 months, Suresh joined with Rs. ‘x’. If Aman’s share from total profit of Rs. 900 ...
Anna and Ben initially invested Rs. 12,500 and Rs. 15,000 in a business venture. Six months into the business, Anna added another Rs. 2,500 to her inves...
- X and Y invested Rs. 48,000 and Rs. 36,000 respectively in a business. After 4 months, Z joined them with an investment of Rs. 30,000. If the annual profit...
Partners P, Q, and R started a company. P invested 36% more than R, and Q invested 54% more than R. If the total profit after a year is Rs. 42000, how m...
‘A’ started a business with the investment of Rs. 12000. After ‘x’ months and after 3 months from starting ‘B’ and ‘C’, respectively, jo...
A and B started a business by investing Rs.300 and Rs.400 respectively. After 6 months, A increased his investment by Rs.800. Find the ratio of annual p...
Three friends, Aman, Bheema, and Chetan, together invested a total of Rs. 9400. After one year, they received profits of Rs. 1440...
'A' and 'B' started a partnership by investing Rs. 9,000 and Rs. 12,000 respectively. 25% of the total profit is given to 'A' for managing the business,...