human
Find Height of Binary Tree represented by Parent array | This functio fills depth of i 'th element in parent[] The depth is filled in depth[i].
If depth [ i ] is already filled.
If node at index i is root.
If depth of parent is not evaluated before , then evaluate depth of parent first.
Depth of this node is depth of parent plus 1.
This function reutns height of binary tree represented by parent array.
Create an array to store depth of all nodes and initialize depth of every node as 0 Depth of root is 1.
fill depth of all nodes.
The height of binary tree is maximum of all depths . Find the maximum in depth [ ] and assign it to ht.
int parent [ ] = { 1 , 5 , 5 , 2 , 2 , - 1 , 3 } ;"
How can the above be solved in Python?
 Can you provide a code to find Height of Binary Tree represented by Parent array and the other steps required?
assistant
#Here is code to find Height of Binary Tree represented by Parent array and the other steps required.
 def fillDepth ( parent , i , depth ) :
	if depth [ i ] != 0 :
		return
	if parent [ i ] == - 1 :
		depth [ i ] = 1
		return
	if depth [ parent [ i ] ] == 0 :
		fillDepth ( parent , parent [ i ] , depth )
	depth [ i ] = depth [ parent [ i ] ] + 1
def findHeight ( parent ) :
	n = len ( parent )
	depth = [ 0 for i in range ( n ) ]
	for i in range ( n ) :
		fillDepth ( parent , i , depth )
	ht = depth [ 0 ]
	for i in range ( 1 , n ) :
		ht = max ( ht , depth [ i ] )
	return ht
parent = [ - 1 , 0 , 0 , 1 , 1 , 3 , 5 ]
print " Height ▁ is ▁ % d " % ( findHeight ( parent ) )