Answers for "the height of a binary tree is given by the height of the root node."

19

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));
}
Posted by: Guest on July-23-2020

Code answers related to "the height of a binary tree is given by the height of the root node."

Browse Popular Code Answers by Language