def max_heapify(seq, i, n):
 l = ((2 * i) + 1)
 r = ((2 * i) + 2)
 if ((l <= n) and (seq[l] > seq[i])):
  largest = l
 else:
  largest = i
 if ((r <= n) and (seq[r] > seq[largest])):
  largest = r
 if (largest != i):
  (seq[i], seq[largest]) = (seq[largest], seq[i])
  max_heapify(seq, largest, n)

def max_heapify ( seq , i , n ) : l = ( ( 2 * i ) + 1 ) r = ( ( 2 * i ) + 2 ) if ( ( l <= n ) and ( seq [ l ] > seq [ i ] ) ) : largest = l else : largest = i if ( ( r <= n ) and ( seq [ r ] > seq [ largest ] ) ) : largest = r if ( largest != i ) : ( seq [ i ] , seq [ largest ] ) = ( seq [ largest ] , seq [ i ] ) max_heapify ( seq , largest , n )
the function of max_heapify is to let the value at seq[i] "float down" in the max-heap so that the subtree rooted at index i becomes a max-heap .