Write a function that computes the maximum width of a dynamically implemented BT. We define the maximum width of a BT as the maximum number of nodes located at the same level.


Difficulty level
This exercise is mostly suitable for students
int width_h(Btree B, int *count)
{
    int left, right;
    if(B)
    {
        left = width_h(B->left, count);
        right = width_h(B->right, count);
        if(left+right > *count)
            *count = left+right ;
        return max(left,right) + 1;
    }
}

int width(Btree B)
{
    int count = 0;
    return width_h(B, &count);
}

Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Implementation of a set using an array of long integers as bits