Complete the code to find the index of the last non-leaf node in the heap array.
last_non_leaf = len(arr) [1] 2 - 1
The last non-leaf node in a heap array is at index len(arr) // 2 - 1. This is because nodes after this index are leaves.
Complete the code to swap elements at indices i and j in the array.
arr[[1]], arr[j] = arr[j], arr[[1]]
To swap elements at indices i and j, use arr[i], arr[j] = arr[j], arr[i].
Fix the error in the condition to check if the left child exists in the heapify function.
if left [1] len(arr):
To check if the left child index is within the array bounds, use left < len(arr).
Fill both blanks to complete the heapify function's recursive call and comparison for the right child.
if right [1] len(arr) and arr[right] [2] arr[largest]: largest = right if largest != i: arr[i], arr[largest] = arr[largest], arr[i] heapify(arr, largest)
The right child index must be less than the array length (right < len(arr)) and its value greater than the current largest (arr[right] > arr[largest]) to update largest.
Fill all three blanks to complete the build_heap function that calls heapify from the last non-leaf node up to the root.
for i in range(len(arr) // 2 - 1, [1], [2]): [3](arr, i)
The loop runs from the last non-leaf node index down to 0 (inclusive), so range(len(arr)//2 - 1, -1, -1). Inside the loop, call heapify(arr, i).
