0
0
Data Structures Theoryknowledge~10 mins

Heap extraction (bubble down) in Data Structures Theory - Interactive Code Practice

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

Complete the code to identify the root element in a max-heap.

Data Structures Theory
root = heap[[1]]
Drag options to blanks, or click blank then click option'
A0
B1
C-1
Dlen(heap)
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 as the root index, which is incorrect for zero-based arrays.
Using -1 or len(heap) which are invalid indices for the root.
2fill in blank
medium

Complete the code to find the left child index of a node at index i in a heap.

Data Structures Theory
left_child = 2 * i [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.
3fill in blank
hard

Fix the error in the condition to check if the right child exists in the heap array.

Data Structures Theory
if right_child_index [1] len(heap):
Drag options to blanks, or click blank then click option'
A<
B<=
C>
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using <= which allows out-of-range index.
Using > or >= which are incorrect for existence check.
4fill in blank
hard

Fill both blanks to correctly swap the parent with the larger child during bubble down.

Data Structures Theory
if heap[[1]] < heap[[2]]:
    heap[[1]], heap[[2]] = heap[[2]], heap[[1]]
Drag options to blanks, or click blank then click option'
Aparent_index
Bleft_child_index
Cright_child_index
Droot_index
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping with the left child when the right child is larger.
Using root_index instead of parent_index.
5fill in blank
hard

Fill all three blanks to complete the bubble down step choosing the larger child correctly.

Data Structures Theory
larger_child = [1] if heap[[2]] > heap[[3]] else [3]
Drag options to blanks, or click blank then click option'
Aleft_child_index
Bright_child_index
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up left and right child indices in the comparison.
Using the same index for both comparison sides.