0
0
DSA C++programming~10 mins

Heap Extract Min or Max Bubble Down in DSA C++ - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to get the index of the left child in a heap array.

DSA C++
int leftChildIndex(int parentIndex) {
    return 2 * parentIndex [1] 1;
}
Drag options to blanks, or click blank then click option'
A*
B-
C+
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction instead of addition.
Using division or multiplication incorrectly.
2fill in blank
medium

Complete the code to swap two elements in the heap array.

DSA C++
void swap(int &a, int &b) {
    int temp = a;
    a = [1];
    b = temp;
}
Drag options to blanks, or click blank then click option'
Ab
Ba
Ctemp
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning 'a' to itself.
Using the wrong variable in assignment.
3fill in blank
hard

Fix the error in the bubble down condition to check if left child exists.

DSA C++
while (leftChild < heapSize && heap[leftChild] [1] heap[index]) {
    // bubble down logic
}
Drag options to blanks, or click blank then click option'
A!=
B>
C==
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' which is for max-heap.
Using equality or inequality operators incorrectly.
4fill in blank
hard

Fill both blanks to correctly find the smaller child index during bubble down.

DSA C++
int smallerChild = (rightChild < heapSize && heap[rightChild] [1] heap[leftChild]) ? [2] : leftChild;
Drag options to blanks, or click blank then click option'
A<
BrightChild
CleftChild
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' instead of '<' in comparison.
Assigning leftChild instead of rightChild when right is smaller.
5fill in blank
hard

Fill all three blanks to complete the bubble down step in extract min operation.

DSA C++
if (heap[index] [1] heap[smallerChild]) {
    swap(heap[index], heap[[2]]);
    index = [3];
} else {
    break;
}
Drag options to blanks, or click blank then click option'
A>
BsmallerChild
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' in comparison.
Swapping with wrong index.
Not updating index correctly.