0
0
Data Structures Theoryknowledge~10 mins

Heapify operation 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 parent index in a heap array.

Data Structures Theory
parent_index = (child_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 normal division '/' which gives a float.
Using addition or multiplication instead of division.
2fill in blank
medium

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

Data Structures Theory
left_child_index = [1] * 2 + 1
Drag options to blanks, or click blank then click option'
Anode
Bchild_index
Cindex
Dparent_index
Attempts:
3 left
💡 Hint
Common Mistakes
Using child_index instead of parent_index.
Forgetting to add 1 after multiplication.
3fill in blank
hard

Fix the error in the heapify function to correctly swap elements when the child is greater than the parent.

Data Structures Theory
if heap[[1]] > heap[parent]:
    heap[[1]], heap[parent] = heap[parent], heap[[1]]
Drag options to blanks, or click blank then click option'
Aindex
Bparent
Cchild
Droot
Attempts:
3 left
💡 Hint
Common Mistakes
Using parent index instead of child index for comparison.
Swapping the wrong elements.
4fill in blank
hard

Fill both blanks to complete the heapify condition that checks if the left child exists and is greater than the parent.

Data Structures Theory
if [1] < len(heap) and heap[[2]] > heap[parent]:
Drag options to blanks, or click blank then click option'
Aleft_child_index
Bright_child_index
Dparent
Attempts:
3 left
💡 Hint
Common Mistakes
Using right_child_index instead of left_child_index.
Comparing with parent index instead of child index.
5fill in blank
hard

Fill all three blanks to complete the dictionary comprehension that maps each node to its heapified value if it is greater than zero.

Data Structures Theory
heapified = [1]: [2] for [1], [2] in enumerate(heap) if [2] > 0}
Drag options to blanks, or click blank then click option'
Aindex
Bvalue
Dnode
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same variable name for both index and value.
Not matching variable names consistently.