“altura del árbol” Código de respuesta

altura de un árbol binario

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));
}
Elegant Elk

altura del árbol

int height(Node* root) {
        // Base Condition : if root is already null. then height must be -1 to make balance with recursion call...
        if(!root) return 0;
        
        // Actual Return statement.. for recursion call..
        return 1 + max(height(root->left), height(root->right));
    }
dK

encontrar la altura de un árbol

// finding height of a binary tree in c++.
int maxDepth(node* node)  
{  
    if (node == NULL)  
        return 0;  
    else
    {  
        /* compute the depth of each subtree */
        int lDepth = maxDepth(node->left);  
        int rDepth = maxDepth(node->right);  
      
        /* use the larger one */
        if (lDepth > rDepth)  
            return(lDepth + 1);  
        else return(rDepth + 1);  
    }  
}  
Enthusiastic Elephant

Calcular la altura del árbol

recursive tree height
khairi abidi

Respuestas similares a “altura del árbol”

Preguntas similares a “altura del árbol”

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código