In: Computer Science
For a Binary Search Tree in C++
void setHeight(TNode *n)(10): This method sets the heights of the nodes in a tree. Once a node is inserted, only the node’s ancestors can have their height changed. Thus you should set the height of the node being inserted (to 1) and then adjust the heights of the node’s parent, grandparent, etc. up until either the height of the node doesn’t change or you hit the root.
1).ANSWER:
GIVEN BELOW:
Theory and pseudo code of the task :The following is the implementation of the pseudo code in c++ :