Question
Consider the following Java code snippet: import java.util.PriorityQueue; import java.util.Comparator; class Item { int priority; String name; public Item(int priority, String name) { this.priority = priority; this.name = name; } @Override public String toString() { return name + "(" + priority + ")"; } } public class HeapQuestion7 { public static void main(String[] args) { // Create a min-heap based on 'priority' PriorityQueue pq = new PriorityQueue(Comparator.comparingInt(item -> item.priority)); pq.add(new Item(5, "Task A")); pq.add(new Item(1, "Task B")); pq.add(new Item(10, "Task C")); pq.add(new Item(3, "Task D")); System.out.println(pq.poll().name); System.out.println(pq.poll().name); } } What will be the output of this program?
More IT Operating System Questions
- The Knuth-Morris-Pratt (KMP) algorithm improves upon the Naive approach by avoiding unnecessary re-comparisons. It achieves this by:
- Consider the following Python code: list_a = [1, 2, 3] tuple_b = (4, 5) string_c = "hello" dict_d = {"key1": 1, "key2": 2} print(len(list_a) + len(tup...
- What is the phenomenon where a process spends more time paging (swapping pages between main memory and disk) than executing instructions?
- Which of the following is NOT a typical step in NLP text preprocessing?
- Which of the following statements accurately describes a guided transmission medium?
- What is the output of the following pseudocode? SET x = 10 SET result = 0 WHILE x > 0 result = result + x x = x - 3 END WHILE PRINT result
- Which of the following is a common technique used in debugging to systematically narrow down the location of a bug?
- Which is best fit for blank space 15?
- What is multi-tenancy in cloud computing?
- Complete the Java method to extract a substring from text starting at startIndex and having length characters. public class StringUtil { public Strin...
Hey! Ask a query
Please enter email id
The email must be a valid email address.
Please enter Mobile Number
Please enter valid Mobile Number
Please enter your Doubt