0
0
DSA Javascriptprogramming~5 mins

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

Choose your learning style9 modes available
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?
A0
Bn - 1
CMath.floor(n / 2) - 1
DMath.floor(n / 2)
Which of the following best describes the heapify operation?
ARearranging a subtree to maintain heap property
BInserting a new element into the heap
CRemoving the root element from the heap
DSorting the entire array
What is the time complexity of building a heap from an unsorted array using heapify?
AO(n log n)
BO(log n)
CO(n^2)
DO(n)
In a max-heap, what is true about the root element?
AIt is the smallest element
BIt is the largest element
CIt is the average of all elements
DIt is always zero
When building a heap, why do we heapify from bottom to top?
ABecause leaf nodes are already heaps
BTo sort the array immediately
CTo insert new elements faster
DTo remove duplicates
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.