Ask Question

Write a program that finds the max binary tree height. (This Is an extremely short piece of code!)

+4
Answers (1)
  1. 12 May, 22:03
    0
    {

    if (root==NULL)

    return 0;

    int l_height=height (root->left); //calculating height of left subtree.

    int r_height=height (root->right); //calculating height of right subtree.

    return 1+max (l_height, r_height); //returning the maximum from left and right height and adding 1 height of root.

    }

    Explanation:

    The above written program is in C++. It find the height of a maximum height of the binary tree. The function uses recursion to find the height.

    First the left subtree's height is calculated then right subtree's then finding the maximum from both of them and adding 1 height of the root.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write a program that finds the max binary tree height. (This Is an extremely short piece of code!) ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers