Question
Java MinHeap class has a heapifyDown method. public class MinHeap { private ArrayList heap; public MinHeap() { heap = new ArrayList<>(); } // ... other methods like insert, getMin ... private void heapifyDown(int
Java MinHeap class has a heapifyDown method. public class MinHeap { private ArrayList heap; public MinHeap() { heap = new ArrayList<>(); } // ... other methods like insert, getMin ... private void heapifyDown(int
i) { int left = 2 * i + 1; int right = 2 * i + 2; int smallest = i; if (left < heap.size() && heap.get(left) < heap.get(smallest)) { smallest = left; } if (right < heap.size() && heap.get(right) < heap.get(smallest)) { smallest = right; } if (smallest !=
i) { // Swap heap.get(i) and heap.get(smallest) int temp = heap.get(i); heap.set(i, heap.get(smallest)); heap.set(smallest, temp); // Bug: Missing recursive call } } } If heapifyDown is called on a node i where its children are not in heap order, but its grandchild is also out of order, what will be the consequence of the missing recursive call?
More IT Operating System Questions
- Consider the following C++ code: #include #include class Printer { public: void print(int num) { std::cout << "Printing int: ...
- Which type of inheritance in C++ allows a class to inherit from more than one base class?
- After fork(), parent and child continue executing. In a typical modern Unix implementation, what memory behavior occurs?
- What is the primary function of a gateway in a network?
- Which query retrieves all records from TableA that have no corresponding records in TableB?
- In the classic bounded-buffer producer-consumer problem using a buffer of size N, to what value should the counting semaphore 'empty' (tracking free buffer...
- Complete the C function to copy at most n characters from source starting at start_index into destination, ensuring destination is null-terminated. Assume ...
- Which unit holds data temporarily and loses it when power is off?
- When an object that has an incoming reference is deleted or deallocated, without modifying the value of the pointer, so that the pointer still points to th...
- A system uses paging with page size 1 KB. Logical address 2500 maps to page 2 (2500 ÷ 1024 = 2 remainder 452), and the page table entry for page 2 gives fr...
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
Think You're Ready for RBI Grade B?
RBI Grade B 2026 Phase 1 Memory Based Paper
- 200 Questions with Detailed Solutions
- Section-wise Coverage (GA, English, Quant & Reasoning)