0
0
DSA Typescriptprogramming~5 mins

Build Heap from Array Heapify in DSA Typescript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AMath.floor(n / 2) - 1
Bn - 1
CMath.floor(n / 2)
D0
Which of the following best describes the heapify operation?
AInserting a new element at the end
BSwapping elements to maintain heap property starting from a node downwards
CSorting the entire array
DRemoving the root element
What is the time complexity of heapify operation on a single node?
AO(n)
BO(n log n)
CO(1)
DO(log n)
When building a heap from an array, why is the overall time complexity O(n) and not O(n log n)?
ABecause heapify is called fewer times on nodes near the bottom which have smaller heights
BBecause the array is already sorted
CBecause heapify is a constant time operation
DBecause only half the elements are heapified
In a max-heap, after heapify, what can be said about the root node?
AIt is the median element
BIt is the smallest element in the heap
CIt is the largest element in the heap
DIt is the last inserted element
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.