0
0
DSA C++programming~10 mins

Heap Insert Operation Bubble Up 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 parent index of a node in a heap.

DSA C++
int parent = (index [1] 1) / 2;
Drag options to blanks, or click blank then click option'
A-
B+
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using + instead of -
Using * or / incorrectly
2fill in blank
medium

Complete the condition to check if the current node is greater than its parent during bubble up.

DSA C++
while (index > 0 && heap[index] [1] heap[parent]) {
Drag options to blanks, or click blank then click option'
A>
B<
C==
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>'
Using '==' which does not trigger swap
3fill in blank
hard

Fix the error in swapping the current node with its parent during bubble up.

DSA C++
int temp = heap[index];
heap[index] = heap[[1]];
heap[parent] = temp;
Drag options to blanks, or click blank then click option'
Aindex
Bparent
C1
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping with the same index
Using a fixed index like 0 or 1
4fill in blank
hard

Fill both blanks to update the index and parent after swapping during bubble up.

DSA C++
index = [1];
parent = (index [2] 1) / 2;
Drag options to blanks, or click blank then click option'
Aparent
Bindex
C-
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using index instead of parent for new index
Adding instead of subtracting in parent calculation
5fill in blank
hard

Fill all three blanks to complete the bubble up loop for heap insert.

DSA C++
while (index > 0 && heap[index] [1] heap[[2]]) {
    int temp = heap[index];
    heap[index] = heap[[3]];
    heap[[2]] = temp;
    index = [2];
    [2] = (index - 1) / 2;
}
Drag options to blanks, or click blank then click option'
A>
Bparent
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' in condition
Mixing up index and parent in swaps