human
Give me a code to given level order traversal of a Binary Tree , check if the Tree is a Min and the other steps required given the following:
Given level order traversal of a Binary Tree , check if the Tree is a Min | Returns true if given level order traversal is Min Heap ..
First non leaf node is at index ( n / 2 - 1 ) . Check whether each parent is greater than child.
Left child will be at index 2 * i + 1 Right child will be at index 2 * i + 2.
If parent is greater than right child.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to given level order traversal of a Binary Tree , check if the Tree is a Min and the other steps required.
 def isMinHeap ( level , n ) :
	for i in range ( int ( n / 2 ) - 1 , - 1 , - 1 ) :
		if level [ i ] > level [ 2 * i + 1 ] :
			return False
		if 2 * i + 2 < n :
			if level [ i ] > level [ 2 * i + 2 ] :
				return False
	return True
if __name__ == ' _ _ main _ _ ' :
	level = [ 10 , 15 , 14 , 25 , 30 ]
	n = len ( level )
	if isMinHeap ( level , n ) :
		print ( " True " )
	else :
		print ( " False " )