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
intermediate
In the context of building a heap, why do we start heapify from the last non-leaf node?
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?
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 'heapify' and 'build heap'.
Heapify is the process of fixing the heap property at a single node, while build heap applies heapify repeatedly from bottom-up to build a heap from an entire array.
Click to reveal answer
beginner
In Go, what data structure is commonly used to represent a heap when building it from an array?
A slice (dynamic array) is used to represent the heap, where parent and child relationships are determined by indices.
Click to reveal answer
When building a max-heap from an array, which node index do you start heapifying from?
✗ Incorrect
Heapify starts from the last non-leaf node because leaf nodes already satisfy the heap property.
What is the parent index of a node at index i in a zero-based array heap?
✗ Incorrect
In zero-based indexing, the parent of node i is at (i - 1) / 2.
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 tree height.
Which of the following best describes the build heap process?
✗ Incorrect
Build heap heapifies all non-leaf nodes from bottom to top to ensure heap property.
After building a max-heap from the array [3, 1, 6, 5, 2, 4], what is the root element?
✗ Incorrect
The max-heap root is the largest element, which is 6.
Describe the step-by-step process of building 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 from an array using heapify is more efficient than inserting elements one by one.
Compare total time complexity of both methods.
You got /3 concepts.