binary trees determining if node' child link is null is simply matter of computing the index of the appropriate child and testing to see if the index is out of range for examplesuppose we want to test if node in the tree from figure has left child since the node is stored at index position we plug this value into the equation for computing the left child indexwhich yields this tells us that if node had left child it would be located within the array at index position but there are only items in the heapstored in positions and would be outside the range of valid node positions this indicates node does not have left child class definition we define the maxheap class for our array-based implementation of the max-heap in listing an array-based version of the heap structure is commonly used when the maximum capacity of the heap is known beforehand if the maximum capacity is not knownthen python list structure can be used instead the array is created with size equal to the maxsize argument supplied to the constructor and assigned to elements since we will be adding one item at time to the heapthe items currently in the heap will only use portion of the arraywith the remaining elements available for new items the count attribute keeps track of how many items are currently in the heap listing the arrayheap py module an array-based implementation of the max-heap class maxheap create max-heap with maximum capacity of maxsize def __init__selfmaxsize )self _elements arraymaxsize self _count return the number of items in the heap def __len__self )return self _count return the maximum capacity of the heap def capacityself )return lenself _elements add new value to the heap def addselfvalue )assert self _count self capacity()"cannot add to full heap add the new value to the end of the list self _elementsself _count value self _count + sift the new value up the tree self _siftupself _count extract the maximum value from the heap def extractself )assert self _count "cannot extract from an empty heap