Recall & Review
beginner
What is the main purpose of the heapify process when building a heap from an array?
Heapify rearranges elements to satisfy the heap property, ensuring each parent node is greater (max-heap) or smaller (min-heap) than its children.
Click to reveal answer
beginner
In a zero-based array representation of a heap, what is the formula to find the left child index of a node at index i?
Left child index = 2 * i + 1
Click to reveal answer
intermediate
Why do we start heapifying from the last non-leaf node when building a heap from an array?
Because leaf nodes already satisfy the heap property, starting from the last non-leaf node ensures all subtrees are heapified bottom-up efficiently.
Click to reveal answer
intermediate
What is the time complexity of building a heap from an unsorted array using heapify?
O(n), where n is the number of elements in the array.
Click to reveal answer
beginner
Explain the difference between max-heap and min-heap in the context of heapify.
In max-heap, heapify ensures parent nodes are greater than children. In min-heap, heapify ensures parent nodes are smaller than children.
Click to reveal answer
What is the index of the last non-leaf node in a zero-based array of size n?
✗ Incorrect
The last non-leaf node is at index Math.floor(n / 2) - 1 because nodes after this index are leaves.
Which of the following best describes the heapify operation?
✗ Incorrect
Heapify fixes the heap property by swapping elements from a node down to its children.
What is the time complexity of heapify operation on a single node?
✗ Incorrect
Heapify on a single node takes O(log n) time because it may move down the height of the heap.
When building a heap from an array, why is the overall time complexity O(n) and not O(n log n)?
✗ Incorrect
Nodes near the bottom have smaller heights, so heapify takes less time on them, making total time O(n).
In a max-heap, after heapify, what can be said about the root node?
✗ Incorrect
In a max-heap, the root node is always the largest element after heapify.
Describe step-by-step how to build a max-heap from an unsorted array using heapify.
Think about fixing the heap property from bottom to top.
You got /4 concepts.
Explain why heapify is more efficient when building a heap from an array compared to inserting elements one by one.
Compare bulk heap construction vs repeated insertions.
You got /4 concepts.