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 from an unsorted array using heapify?
The time complexity is 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.
Max-heap ensures each parent node is greater than its children; min-heap ensures each parent node is smaller than its children. Heapify adjusts nodes accordingly.
Click to reveal answer
What is the index of the last non-leaf node in a heap stored as an array of size n?
✗ Incorrect
The last non-leaf node is at index n/2 - 1 in zero-based indexing.
Which of the following best describes the heapify operation?
✗ Incorrect
Heapify fixes the heap property by moving a node downwards if needed.
What is the time complexity of heapify operation on a single node in a heap of size n?
✗ Incorrect
Heapify on a single node takes O(log n) time because it may move down the height of the heap.
When building a max-heap from an array, which property must be true after heapify is applied to a node?
✗ Incorrect
In a max-heap, each parent node must be greater than or equal to its children.
Which of these is NOT a step in building a heap from an array using heapify?
✗ Incorrect
Sorting the array is not part of building a heap; heapify rearranges elements to satisfy heap property.
Describe the process of building a heap from an unsorted array using heapify.
Think about fixing subtrees from bottom to top.
You got /4 concepts.
Explain why the build heap operation using heapify is more efficient than inserting elements one by one into an empty heap.
Compare total time complexities and approach.
You got /4 concepts.