Heaps Operations Quiz
40 comprehensive questions exploring heap operations — with 16 code examples covering insert, extract-min/max, peek, heapify-up/down, and time complexity in this cpp quiz.
Question 1
What is a heap insert operation?
Question 2
How does heapify-up work in insertion?
Compare with parent
Swap if violates heap property
Continue until root or property satisfiedQuestion 3
What is the worst-case time complexity of heap insert?
Question 4
How does heap extract-min work?
Remove root, replace with last element
Heapify-down to maintain propertyQuestion 5
What is heapify-down operation?
Question 6
What is the time complexity of heap extract-min?
Extract: O(log n)
Heapify-down through heightQuestion 7
What is the peek operation in heaps?
Question 8
How does heapify-up compare to heapify-down?
Heapify-up: from leaf to root
Heapify-down: from root to leafQuestion 9
What happens during heap insert when the element is larger than its parent?
Question 10
How does heap extract handle the last element replacement?
Replace root with last element
Then heapify-down from rootQuestion 11
What is the best-case time complexity of heap insert?
Question 12
How does heapify-down choose which child to swap with?
Compare both children
Swap with smaller/larger childQuestion 13
What is the amortized cost of heap operations?
Question 14
How does heap insert handle array resizing?
Check array capacity
Resize if needed before insertionQuestion 15
What is the relationship between heap height and operation time?
Question 16
How does heap extract-min handle empty heaps?
Check if heap is empty
Return error or special valueQuestion 17
What is the space complexity of heap operations?
Question 18
How does heap insert maintain stability?
Stability: equal elements maintain order
Heapify may break stabilityQuestion 19
What is the difference between peek and extract operations?
Question 20
How does heapify-down handle nodes with one child?
Check if only one child exists
Compare with existing child onlyQuestion 21
What is the impact of heap operations on cache performance?
Question 22
How does heap extract-min handle the heap size reduction?
Decrement heap size after extraction
Last element becomes garbageQuestion 23
What is the worst-case path for heapify-up?
Question 24
How does heap insert handle duplicate values?
Duplicates allowed
Heap property still maintainedQuestion 25
What is the average-case performance of heap operations?
Question 26
How does heapify-down terminate?
Continue until: at leaf level
Or heap property satisfied with both childrenQuestion 27
What is the constant factors in heap operation complexity?
Question 28
How does heap insert work with custom comparators?
Use comparator for parent-child comparisons
Maintain heap property with custom orderingQuestion 29
What is the heap property violation detection?
Question 30
How does heap extract-min handle the boundary case of size 1?
Size 1: root is min, remove it
Heap becomes emptyQuestion 31
What is the recursive nature of heapify operations?
Question 32
How does heap insert affect heap height?
Insert may increase height
When array needs expansionQuestion 33
What is the relationship between heap operations and complete binary trees?
Question 34
How does heapify-up handle the root case?
When current node is root
Heapify-up terminatesQuestion 35
What is the impact of heap operations on stability?
Question 36
How does heap extract-min maintain the complete tree property?
Size reduction maintains completeness
No gaps in array representationQuestion 37
What is the difference between heap operations in min-heap vs max-heap?
Question 38
How does heap insert handle overflow conditions?
Check size vs capacity
Resize array if neededQuestion 39
What is the practical performance difference between heapify-up and heapify-down?
Question 40
Considering heap operations and their implementation challenges, which fundamental property makes heapify procedures essential for maintaining the heap invariant despite the complexity of parent-child comparisons and potential element reordering?
