node height of a simple tree where edges details are given code example
Example 1: find height of binary search tree python
def getHeight(self,root):
return -1 if root is None else 1 + max(self.getHeight(root.left), self.getHeight(root.right))
Example 2: height of a binary tree
int height(Node* root)
{
// Base case: empty tree has height 0
if (root == nullptr)
return 0;
// recur for left and right subtree and consider maximum depth
return 1 + max(height(root->left), height(root->right));
}