#NEWLINE# @ staticmethod #NEWLINE# def FixDown( heap , i , j ) : #NEWLINE# #INDENT# 'Traverse down the heap, ensuring the invariant is maintained.\n\n    Args:\n      heap - The heap array.\n      i, j - The node index to traverse from -> to.\n    ' #NEWLINE# while True : #NEWLINE# #INDENT# if ( j < ( i * 2 ) ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# m = ( ( 2 * i ) if ( ( j == ( i * 2 ) ) or ( heap [ ( 2 * i ) ] < heap [ ( ( 2 * i ) + 1 ) ] ) ) else ( ( 2 * i ) + 1 ) ) #NEWLINE# if ( heap [ m ] < heap [ i ] ) : #NEWLINE# #INDENT# Heap . Swap ( heap , i , m ) #NEWLINE# i = j #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# break