Recall & Review
beginner
What is the purpose of the 'bubble down' operation in a heap after extracting the min or max element?
The 'bubble down' operation restores the heap property by moving the root element down the tree, swapping it with its smaller (min-heap) or larger (max-heap) child until the heap order is correct.
Click to reveal answer
beginner
In a min-heap, after extracting the minimum element, which element replaces the root before bubbling down?
The last element in the heap replaces the root before the bubble down process begins to restore the heap property.
Click to reveal answer
intermediate
What condition determines when to stop the bubble down process in a heap?
Bubble down stops when the current node is smaller (min-heap) or larger (max-heap) than both its children or when it has no children.
Click to reveal answer
intermediate
Why do we swap the current node with the smaller (min-heap) or larger (max-heap) child during bubble down?
Swapping ensures the heap property is maintained by moving the out-of-place element down to a position where it is correctly ordered relative to its children.
Click to reveal answer
beginner
Show the TypeScript signature of a bubble down function for a min-heap.
function bubbleDown(heap: number[], index: number): voidClick to reveal answer
What element is removed during the extract operation in a min-heap?
✗ Incorrect
In a min-heap, the root element is the minimum and is removed during extraction.
After removing the root in a max-heap, which element temporarily replaces the root before bubbling down?
✗ Incorrect
The last element replaces the root temporarily before bubble down restores the heap.
During bubble down in a min-heap, you swap the current node with:
✗ Incorrect
In a min-heap, bubble down swaps with the smaller child to maintain heap order.
When does the bubble down process stop?
✗ Incorrect
Bubble down stops when the heap property is restored or no children exist.
What is the time complexity of the bubble down operation in a heap?
✗ Incorrect
Bubble down takes O(log n) time because it moves down the height of the heap.
Explain step-by-step how the bubble down operation works after extracting the root in a min-heap.
Think about how the heap property is maintained by moving the root down.
You got /4 concepts.
Describe why bubble down is necessary after extracting the min or max element from a heap.
Consider what happens to the heap shape and order after extraction.
You got /4 concepts.