human
How to check if a given array represents a Binary Heap ? | Returns true if arr [ i . . n - 1 ] represents a max - heap.
Start from root and go till the last internal node.
If left child is greater , return false.
If right child is greater , return false.
Driver Code"
Solution in Python:
 Can you provide a code to how to check if a given array represents a Binary Heap?
assistant
#Here is code to how to check if a given array represents a Binary Heap .
 def isHeap ( arr , n ) :
	for i in range ( int ( ( n - 2 ) / 2 ) + 1 ) :
		if arr [ 2 * i + 1 ] > arr [ i ] :
			return False
		if ( 2 * i + 2 < n and arr [ 2 * i + 2 ] > arr [ i ] ) :
			return False
	return True
if __name__ == ' _ _ main _ _ ' :
	arr = [ 90 , 15 , 10 , 7 , 12 , 2 , 7 , 3 ]
	n = len ( arr )
	if isHeap ( arr , n ) :
		print ( " Yes " )
	else :
		print ( " No " )