Answers for "height of bst cpp"

C++
0

height of bst cpp

// Find height of a tree, defined by the root node
int tree_height(Node* root) {
    if (root == NULL) 
        return 0;
    else {
        // Find the height of left, right subtrees
        left_height = tree_height(root->left);
        right_height = tree_height(root->right);
          
        // Find max(subtree_height) + 1 to get the height of the tree
        return max(left_height, right_height) + 1;
}
Posted by: Guest on October-10-2021

Browse Popular Code Answers by Language