Recall & Review
beginner
What is the 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 are the indices of the left and right children of the node at index i?
Left child index = 2 * i + 1, Right child index = 2 * i + 2.
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 become heaps efficiently.
Click to reveal answer
intermediate
What is the time complexity of building a heap using the heapify method on an array of size n?
The time complexity is O(n), which is more efficient than repeatedly inserting elements (O(n log n)).
Click to reveal answer
beginner
Explain the difference between max-heapify and min-heapify.
Max-heapify ensures each parent node is greater than its children, while min-heapify ensures each parent node is smaller than its children.
Click to reveal answer
What is the index of the last non-leaf node in a heap array of size n?
✗ Incorrect
The last non-leaf node is at index Math.floor(n / 2) - 1 because nodes after this are leaves.
Which of the following best describes the heapify operation?
✗ Incorrect
Heapify fixes the heap property in a subtree rooted at a given node.
What is the time complexity of building a heap from an unsorted array using heapify?
✗ Incorrect
Building a heap using heapify runs in O(n) time.
In a max-heap, what is true about the root element?
✗ Incorrect
The root of a max-heap is the largest element.
When building a heap, why do we heapify from bottom to top?
✗ Incorrect
Leaf nodes satisfy heap property, so heapifying bottom-up fixes all subtrees efficiently.
Describe the steps to build a max-heap from an unsorted array using heapify.
Think about fixing subtrees from bottom to top.
You got /4 concepts.
Explain why building a heap using heapify is more efficient than inserting elements one by one.
Compare time complexities and approach.
You got /4 concepts.