Recall & Review
beginner
What is the purpose of the bubble up operation in a heap insert?
The bubble up operation restores the heap property by moving the newly inserted element up the tree until it is in the correct position.
Click to reveal answer
beginner
In a min-heap, when does the bubble up operation stop during insertion?
It stops when the inserted element is greater than or equal to its parent or when it reaches the root of the heap.
Click to reveal answer
intermediate
What is the time complexity of the bubble up operation in a heap insert?
The time complexity is O(log n), where n is the number of elements in the heap, because the element moves up at most the height of the heap.
Click to reveal answer
intermediate
Explain the relationship between the child and parent indices in a heap array during bubble up.
For a child at index i, the parent index is (i-1)/2 (integer division). Bubble up compares the child with this parent to decide if swapping is needed.
Click to reveal answer
beginner
Why is bubble up important for maintaining heap structure after insertion?
Because inserting at the end may break the heap property, bubble up fixes this by moving the new element up until the heap property is restored.
Click to reveal answer
What is the first step after inserting a new element at the end of a heap array?
✗ Incorrect
After insertion at the end, bubble up moves the element up to maintain the heap property.
In a max-heap, bubble up swaps the inserted element with its parent if:
✗ Incorrect
In max-heap, bubble up swaps when the child is larger than the parent to maintain max-heap property.
What is the parent index of the element at index 5 in a heap array?
✗ Incorrect
Parent index = (5-1)/2 = 4/2 = 2.
Which of these best describes the heap property?
✗ Incorrect
In a min-heap, each parent node is smaller than or equal to its children.
What is the worst-case number of swaps during bubble up in a heap of size n?
✗ Incorrect
Bubble up swaps at most the height of the heap, which is O(log n).
Describe the bubble up process during heap insertion and why it is necessary.
Think about how the new element moves up to keep the heap order.
You got /4 concepts.
Explain how to calculate the parent index of a node in a heap stored as an array.
Remember the heap is a complete binary tree stored in an array.
You got /4 concepts.