Doubt - pls explain clearly

Actually when we compute height of tree we add 1 everytime in backward direction from NULL here it is not present in code can you pls explain ?
like the code should also have return h1+h2+1

hello @shyama

note in height we are computing number of nodes.
whereas in diameter we are computing the number of edges.

when we are saying h1 height of subtree is equivalent to h1-1 edges.
now to join subtree with root , we need one more edges so h1-1 + 1 = h1 edges.

similarly for right subtree , we have h2-1 edges, add one edge between root and right subtree the edges will be h2-1+1=h2 edges

the diameter is h1+h2

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.