Lab 4 Q 1 B
Lab 4 Q 1 B
// Step 4: Restore the heap property by moving the new root down
i = 1
while true:
leftChild = 2 * i
rightChild = 2 * i + 1
smallest = i
// Find the smallest among the root, left child, and right child
if leftChild ≤ heapSize and H[leftChild] < H[smallest]:
smallest = leftChild