human
Give me a code to how to check if a given array represents a Binary Heap given the following:
How to check if a given array represents a Binary Heap ? | Returns true if arr [ i . . n - 1 ] represents a max - heap.
If a leaf node.
If an internal node and is greater than its children , and same is recursively true for the children.
Driver Code"
Solution in Python:
assistant
#Here is code to how to check if a given array represents a Binary Heap .
 def isHeap ( arr , i , n ) :
	if i >= int ( ( n - 2 ) / 2 ) :
		return True
	if ( arr [ i ] >= arr [ 2 * i + 1 ] and arr [ i ] >= arr [ 2 * i + 2 ] and isHeap ( arr , 2 * i + 1 , n ) and isHeap ( arr , 2 * i + 2 , n ) ) :
		return True
	return False
if __name__ == ' _ _ main _ _ ' :
	arr = [ 90 , 15 , 10 , 7 , 12 , 2 , 7 , 3 ]
	n = len ( arr ) - 1
	if isHeap ( arr , 0 , n ) :
		print ( " Yes " )
	else :
		print ( " No " )