Hi there. I'd like to know if following code is correct to verify if a tree is complete. From my test cases it works but i could easily be overlooking something.

I just check each node to see if height of right subtree is bigger, we know in complete binary tree that can never happen, they must be equal or left can be bigger. Left subtree can be bigger but difference can't be more than one, that's what i check also.

Is there something else i'am missing?



Code:
int height (Node* root)
{
    if (root == NULL)
    {
        return -1;
    }    
    return max(height(root->left), height(root->right))+ 1;
}

int max(int a, int b)
{
    if (a > b)
    {
        return a;
    }
    return b;
}

int isCompleteBST(Node* root)
{
    if (root == NULL)
    {
        return 1;
    }
    if (height(root->left) - height(root->right) > 1 || height(root->right) > height(root->left))
    {
        return 0;
    }    
    if (!isCompleteBST(root->left) || !isCompleteBST(root->right))
    {
        return 0;
    }
    return 1;
}