educative.io

Why minHeapify() called with all elements of Heap ? Is it same as calling minHeapify() with only parent nodes in Heap?

def buildHeap(self, arr):
self.heap = arr
for i in range(len(arr)-1, -1, -1):
self.__minHeapify(i)

index_of _parent = ((len(arr)-1)-1)//2 # parent_index = floor((last_index - 1)/2)

Hi @Naveen_Doppa ,
Thank you so much for reaching out to us.

Yes, we can simply start calling __minHeapify() from the last parent but calling it from the last child won’t increase the complexity of the algorithm. The cost is very minimal so we can simply ignore it.

If you there is anything else I can help you with, please let me know.