1.

The height of a tree is the length of the longest path in the tree from root to any leaf. Write an algorithmic function, which takes the value of a pointer to the root of the tree, then computes and prints the height of the tree and a path of that length. 

Answer»

Height(Left,Right,Root,height)

1. If Root=Null then height=0; 

return; 

2. height(Left,Right,Left(Root),heightL) 

3. height(Left,Right,Right(Root),heightR) 

4. If heightL≥heightR then 

height=heightL+1; 

Else 

height=heightR+1; 

5. Return 



Discussion

No Comment Found

Related InterviewSolutions