0
0
DSA Javascriptprogramming~5 mins

Heap Extract Min or Max Bubble Down in DSA Javascript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the 'bubble down' operation in a heap after extracting the min or max?
The 'bubble down' operation restores the heap property by moving the root element down the tree to its correct position after extraction, ensuring the heap remains a valid min-heap or max-heap.
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 starts.
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 with the smaller or larger child maintains the heap property by ensuring the parent node is always less than (min-heap) or greater than (max-heap) its children.
Click to reveal answer
advanced
Show the bubble down steps after extracting the max from this max-heap: [50, 30, 40, 10, 20]
1. Remove max (50), replace root with last element (20): [20, 30, 40, 10] 2. Compare 20 with children 30 and 40; swap with 40 (largest child): [40, 30, 20, 10] 3. Now 20 has no children, so stop. Final heap: [40, 30, 20, 10]
Click to reveal answer
What element replaces the root in a heap after extracting the min or max?
AThe second last element
BThe first child of the root
CA new random element
DThe last element in the heap
In a min-heap, bubble down swaps the current node with which child?
AThe larger child
BThe smaller child
CThe left child always
DThe right child always
When does the bubble down process stop?
AWhen the node is in correct order with children or has no children
BWhen the node is smaller than its children in a max-heap
CWhen the node is larger than its children in a min-heap
DAfter a fixed number of swaps
What is the time complexity of bubble down in a heap of size n?
AO(n)
BO(1)
CO(log n)
DO(n log n)
Which of these is NOT true about bubble down?
AIt always swaps with the left child
BIt restores heap property after extraction
CIt swaps with the child violating heap property
DIt stops when heap property is satisfied
Explain the bubble down process after extracting the root from a min-heap.
Think about how to keep the smallest element at the root.
You got /4 concepts.
    Describe why bubble down is necessary after extracting the max from a max-heap.
    Consider what happens to the heap structure after removal.
    You got /4 concepts.